Skip to content

Commit

Permalink
Issue #56 - Code and Styles set-up for Light Theme implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
GrazianoCapelli committed Dec 29, 2019
1 parent 8148e2a commit 5fbcc1b
Show file tree
Hide file tree
Showing 23 changed files with 381 additions and 101 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
minSdkVersion 14
targetSdkVersion 28
versionCode 28
versionName '2.2.5b_20191220'
versionName '2.2.5b_20191229'
}
buildTypes {
debug {
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
android:networkSecurityConfig="@xml/network_security_config"
android:icon="@mipmap/gps_logger"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/MyMaterialTheme">
android:theme="@style/MyMaterialTheme"
android:supportsRtl="true">
<activity android:name=".GPSActivity"
android:label="@string/app_name"
android:exported="true"
Expand All @@ -48,6 +48,7 @@
</intent-filter>
</activity>
<activity android:name=".SettingsActivity"
android:theme="@style/MySettingsTheme"
android:label="@string/menu_settings"
android:launchMode="singleTask"
android:configChanges="orientation|screenSize">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.TypedArray;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
Expand All @@ -39,7 +40,12 @@ public class FragmentAboutDialog extends DialogFragment {
//@SuppressLint("InflateParams")
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder createAboutAlert = new AlertDialog.Builder(getActivity(), R.style.MyMaterialThemeAbout);
int[] attrs1 = {R.attr.MyMaterialThemeAbout_ref};
TypedArray ta1 = getContext().obtainStyledAttributes(attrs1);
int indexOfMaterialThemeAboutStyle = ta1.getResourceId(0, R.style.MyMaterialThemeAbout);
ta1.recycle();

AlertDialog.Builder createAboutAlert = new AlertDialog.Builder(getActivity(), indexOfMaterialThemeAboutStyle);

LayoutInflater inflater = getActivity().getLayoutInflater();
final View view = inflater.inflate(R.layout.fragment_about_dialog, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
Expand All @@ -46,6 +47,9 @@ public class FragmentGPSFix extends Fragment {
private final int GPS_STABILIZING = 4;
private final int GPS_OK = 5;

int indexOftextColorPrimary = 0;
int indexOftextColorSecondary = 0;

private PhysicalDataFormatter phdformatter = new PhysicalDataFormatter();

private FrameLayout FLGPSFix;
Expand Down Expand Up @@ -108,6 +112,16 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_gpsfix, container, false);

int[] attrs1 = {R.attr.textColorPrimary};
TypedArray ta1 = getContext().obtainStyledAttributes(attrs1);
indexOftextColorPrimary = ta1.getResourceId(0, android.R.color.black);
ta1.recycle();

int[] attrs2 = {R.attr.textColorSecondary};
TypedArray ta2 = getContext().obtainStyledAttributes(attrs2);
indexOftextColorSecondary = ta2.getResourceId(0, android.R.color.black);
ta2.recycle();

FLGPSFix = (FrameLayout) view.findViewById(R.id.id_fragmentgpsfixFrameLayout);

TVLatitude = (TextView) view.findViewById(R.id.id_textView_Latitude);
Expand Down Expand Up @@ -211,8 +225,8 @@ public void Update() {

// Colorize the Altitude textview depending on the altitude EGM Correction
isValidAltitude = EGMAltitudeCorrection && (location.getAltitudeEGM96Correction() != NOT_AVAILABLE);
TVAltitude.setTextColor(isValidAltitude ? getResources().getColor(R.color.textColorPrimary) : getResources().getColor(R.color.textColorSecondary));
TVAltitudeUM.setTextColor(isValidAltitude ? getResources().getColor(R.color.textColorPrimary) : getResources().getColor(R.color.textColorSecondary));
TVAltitude.setTextColor(isValidAltitude ? getResources().getColor(indexOftextColorPrimary) : getResources().getColor(indexOftextColorSecondary));
TVAltitudeUM.setTextColor(isValidAltitude ? getResources().getColor(indexOftextColorPrimary) : getResources().getColor(indexOftextColorSecondary));

TVGPSFixStatus.setVisibility(View.GONE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void ontoggleRecordGeoPoint(View view) {
boolean newRecordingState = !grs;
gpsApplication.setRecording(newRecordingState);
EventBus.getDefault().post(EventBusMSG.UPDATE_TRACK);
tableLayoutGeoPoints.setBackgroundColor(newRecordingState ? getResources().getColor(R.color.colorPrimary) : getResources().getColor(R.color.colorTrackBackground));
tableLayoutGeoPoints.setBackgroundColor(newRecordingState ? getResources().getColor(R.color.colorPrimary) : getResources().getColor(R.color.colorTransparent));
}
}

Expand All @@ -107,7 +107,7 @@ public void onPlacemarkRequest(View view) {
final Boolean pr = gpsApplication.getPlacemarkRequest();
boolean newPlacemarkRequestState = !pr;
gpsApplication.setPlacemarkRequest(newPlacemarkRequestState);
tableLayoutPlacemarks.setBackgroundColor(newPlacemarkRequestState ? getResources().getColor(R.color.colorPrimary) : getResources().getColor(R.color.colorTrackBackground));
tableLayoutPlacemarks.setBackgroundColor(newPlacemarkRequestState ? getResources().getColor(R.color.colorPrimary) : getResources().getColor(R.color.colorTransparent));
}
}

Expand All @@ -129,9 +129,9 @@ public void Update() {
if (TVPlacemarks != null)
TVPlacemarks.setText(String.valueOf(track.getNumberOfPlacemarks()));
if (tableLayoutGeoPoints != null)
tableLayoutGeoPoints.setBackgroundColor(grs ? getResources().getColor(R.color.colorPrimary) : getResources().getColor(R.color.colorTrackBackground));
tableLayoutGeoPoints.setBackgroundColor(grs ? getResources().getColor(R.color.colorPrimary) : getResources().getColor(R.color.colorTransparent));
if (tableLayoutPlacemarks != null)
tableLayoutPlacemarks.setBackgroundColor(pr ? getResources().getColor(R.color.colorPrimary) : getResources().getColor(R.color.colorTrackBackground));
tableLayoutPlacemarks.setBackgroundColor(pr ? getResources().getColor(R.color.colorPrimary) : getResources().getColor(R.color.colorTransparent));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package eu.basicairdata.graziano.gpslogger;

import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
Expand All @@ -32,6 +33,9 @@

public class FragmentTrack extends Fragment {

int indexOftextColorPrimary = 0;
int indexOftextColorSecondary = 0;

private PhysicalDataFormatter phdformatter = new PhysicalDataFormatter();

private TextView TVDuration;
Expand Down Expand Up @@ -87,6 +91,16 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_track, container, false);

int[] attrs1 = {R.attr.textColorPrimary};
TypedArray ta1 = getContext().obtainStyledAttributes(attrs1);
indexOftextColorPrimary = ta1.getResourceId(0, android.R.color.black);
ta1.recycle();

int[] attrs2 = {R.attr.textColorSecondary};
TypedArray ta2 = getContext().obtainStyledAttributes(attrs2);
indexOftextColorSecondary = ta2.getResourceId(0, android.R.color.black);
ta2.recycle();

TVDuration = (TextView) view.findViewById(R.id.id_textView_Duration);
TVTrackID = (TextView) view.findViewById(R.id.id_textView_TrackIDLabel);
TVTrackName = (TextView) view.findViewById(R.id.id_textView_TrackName);
Expand Down Expand Up @@ -167,8 +181,8 @@ public void Update() {

// Colorize the Altitude Gap textview depending on the altitude filter
isValidAltitude = track.isValidAltitude();
TVAltitudeGap.setTextColor(isValidAltitude ? getResources().getColor(R.color.textColorPrimary) : getResources().getColor(R.color.textColorSecondary));
TVAltitudeGapUM.setTextColor(isValidAltitude ? getResources().getColor(R.color.textColorPrimary) : getResources().getColor(R.color.textColorSecondary));
TVAltitudeGap.setTextColor(isValidAltitude ? getResources().getColor(indexOftextColorPrimary) : getResources().getColor(indexOftextColorSecondary));
TVAltitudeGapUM.setTextColor(isValidAltitude ? getResources().getColor(indexOftextColorPrimary) : getResources().getColor(indexOftextColorSecondary));

TVTrackStatus.setVisibility(View.INVISIBLE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.TypedArray;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
Expand Down Expand Up @@ -73,6 +74,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_tracklist, container, false);

TVTracklistEmpty = (TextView) view.findViewById(R.id.id_textView_TracklistEmpty);
recyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view);
recyclerView.setHasFixedSize(true);
Expand All @@ -82,6 +84,22 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
recyclerView.getItemAnimator().setChangeDuration(0);
adapter = new TrackAdapter(data);
recyclerView.setAdapter(adapter);

int[] attrs1 = {R.attr.colorCardBackground};
TypedArray ta1 = getContext().obtainStyledAttributes(attrs1);
adapter.indexOfcolorCardBackground = ta1.getResourceId(0, android.R.color.black);
ta1.recycle();

int[] attrs2 = {R.attr.colorCardBackground_Selected};
TypedArray ta2 = getContext().obtainStyledAttributes(attrs2);
adapter.indexOfcolorCardBackground_Selected = ta2.getResourceId(0, android.R.color.black);
ta2.recycle();

int[] attrs3 = {R.attr.isLightTheme};
TypedArray ta3 = getContext().obtainStyledAttributes(attrs3);
adapter.isLightTheme = ta3.getBoolean(0, false);
ta3.recycle();

return view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.ColorMatrixColorFilter;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
Expand All @@ -40,8 +41,19 @@

class TrackAdapter extends RecyclerView.Adapter<TrackAdapter.TrackHolder> {

private static final float[] NEGATIVE = {
-1.0f, 0, 0, 0, 210, // red
0, -1.0f, 0, 0, 210, // green
0, 0, -1.0f, 0, 210, // blue
0, 0, 0, 0.75f, 0 // alpha
};

private final static int NOT_AVAILABLE = -100000;

public int indexOfcolorCardBackground = 0;
public int indexOfcolorCardBackground_Selected = 0;
public boolean isLightTheme = false;

private List<Track> dataSet;

private static final Bitmap[] bmpTrackType = {
Expand Down Expand Up @@ -86,7 +98,7 @@ class TrackHolder extends RecyclerView.ViewHolder implements View.OnClickListene
public void onClick(View v) {
if (GPSApplication.getInstance().getJobsPending() == 0) {
track.setSelected(!track.isSelected());
card.setCardBackgroundColor(GPSApplication.getInstance().getResources().getColor(track.isSelected() ? R.color.colorCardBackground_Selected : R.color.colorCardBackground));
card.setCardBackgroundColor(GPSApplication.getInstance().getResources().getColor(track.isSelected() ? indexOfcolorCardBackground_Selected : indexOfcolorCardBackground));
EventBus.getDefault().post(new EventBusMSGNormal(track.isSelected() ? EventBusMSG.TRACKLIST_SELECT : EventBusMSG.TRACKLIST_DESELECT, track.getId()));
//Log.w("myApp", "[#] TrackAdapter.java - Selected track id = " + id);
}
Expand Down Expand Up @@ -116,6 +128,12 @@ public void onClick(View v) {
imageViewThumbnail = itemView.findViewById(R.id.id_imageView_card_minimap);
imageViewPulse = itemView.findViewById(R.id.id_imageView_card_pulse);
imageViewIcon = itemView.findViewById(R.id.id_imageView_card_tracktype);

if (isLightTheme) {
imageViewThumbnail.setColorFilter(new ColorMatrixColorFilter(NEGATIVE));
imageViewPulse.setColorFilter(new ColorMatrixColorFilter(NEGATIVE));
imageViewIcon.setColorFilter(new ColorMatrixColorFilter(NEGATIVE));
}
}


Expand Down Expand Up @@ -166,7 +184,7 @@ void UpdateTrackStats(Track trk) {
void BindTrack(Track trk) {
track = trk;

card.setCardBackgroundColor(GPSApplication.getInstance().getResources().getColor(track.isSelected() ? R.color.colorCardBackground_Selected : R.color.colorCardBackground));
card.setCardBackgroundColor(GPSApplication.getInstance().getResources().getColor(track.isSelected() ? indexOfcolorCardBackground_Selected : indexOfcolorCardBackground));

imageViewPulse.setVisibility(View.INVISIBLE);
textViewTrackName.setText(track.getName());
Expand Down Expand Up @@ -215,6 +233,7 @@ void BindTrack(Track trk) {


TrackAdapter(List<Track> data) {

synchronized(data) {
this.dataSet = data;
}
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/res/drawable/rounded_corner_light.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ rounded_corner_light.xml
~ Created by G.Capelli (BasicAirData) on 29/12/2019
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="@color/colorRoundedCornerDarkBottom_Light"
android:endColor="@color/colorRoundedCornerDarktop_Light"
android:angle="90"/>
<corners android:bottomRightRadius="2dp" android:bottomLeftRadius="2dp"
android:topLeftRadius="2dp" android:topRightRadius="2dp" />
<stroke android:width="1dp" android:color="@color/colorRoundedCornerDarkBorder_Light"/>
</shape>
14 changes: 7 additions & 7 deletions app/src/main/res/layout-land/fragment_gpsfix.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_corner_dark"
android:background="?attr/TileDrawable_ref"
android:layout_margin="3dp"
android:id="@+id/id_TableLayout_Coordinates"
android:visibility="invisible">
Expand Down Expand Up @@ -154,7 +154,7 @@
android:id="@+id/id_TableLayout_Time"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:background="@drawable/rounded_corner_dark"
android:background="?attr/TileDrawable_ref"
android:layout_margin="3dp"
android:visibility="invisible">

Expand Down Expand Up @@ -193,7 +193,7 @@
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:layout_margin="3dp"
android:background="@drawable/rounded_corner_dark"
android:background="?attr/TileDrawable_ref"
android:visibility="invisible">

<TableRow
Expand Down Expand Up @@ -239,7 +239,7 @@
android:id="@+id/id_TableLayout_Altitude"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:background="@drawable/rounded_corner_dark"
android:background="?attr/TileDrawable_ref"
android:layout_margin="3dp"
android:visibility="invisible">

Expand Down Expand Up @@ -285,7 +285,7 @@
android:id="@+id/id_TableLayout_Accuracy"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:background="@drawable/rounded_corner_dark"
android:background="?attr/TileDrawable_ref"
android:layout_margin="3dp"
android:visibility="invisible">

Expand Down Expand Up @@ -341,7 +341,7 @@
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:layout_margin="3dp"
android:background="@drawable/rounded_corner_dark"
android:background="?attr/TileDrawable_ref"
android:visibility="invisible">

<TableRow
Expand Down Expand Up @@ -386,7 +386,7 @@
android:id="@+id/id_TableLayout_Bearing"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:background="@drawable/rounded_corner_dark"
android:background="?attr/TileDrawable_ref"
android:layout_margin="3dp"
android:visibility="invisible">

Expand Down
Loading

0 comments on commit 5fbcc1b

Please sign in to comment.