Skip to content

Commit

Permalink
Support RTL
Browse files Browse the repository at this point in the history
  • Loading branch information
Protino committed Nov 11, 2016
1 parent 31bb510 commit a4cebd7
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class MainActivity extends AppCompatActivity implements ForecastFragment.Callback {

private static final String TAG = MainActivity.class.getSimpleName();
private static final String DETAILFRAGMENT_TAG = "DFTAG";
private static final String DETAIL_FRAGMENT_TAG = "DFTAG";
private static final String PANE_TYPE = "pane_type";
private static boolean mTwoPane;
private String mLocation;
Expand All @@ -37,7 +37,7 @@ protected void onCreate(Bundle savedInstanceState) {

if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.weather_detail_container, new DetailFragment(), DETAILFRAGMENT_TAG)
.replace(R.id.weather_detail_container, new DetailFragment(), DETAIL_FRAGMENT_TAG)
.commit();
}
} else {
Expand Down Expand Up @@ -110,7 +110,7 @@ protected void onResume() {
if (null != ff) {
ff.onLocationChanged();
}
DetailFragment df = (DetailFragment) getSupportFragmentManager().findFragmentByTag(DETAILFRAGMENT_TAG);
DetailFragment df = (DetailFragment) getSupportFragmentManager().findFragmentByTag(DETAIL_FRAGMENT_TAG);
if (null != df) {
df.onLocationChanged(location);
}
Expand All @@ -128,7 +128,7 @@ public void onItemSelected(Uri dateUri) {
fragment.setArguments(bundle);

getSupportFragmentManager().beginTransaction()
.replace(R.id.weather_detail_container, fragment, DETAILFRAGMENT_TAG)
.replace(R.id.weather_detail_container, fragment, DETAIL_FRAGMENT_TAG)
.commit();

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceManager;
Expand Down Expand Up @@ -80,7 +81,22 @@ public boolean onPreferenceChange(Preference preference, Object value) {
}
} else {
// For other preferences, set the summary to the value's simple string representation.
if (!(preference instanceof CheckBoxPreference)) preference.setSummary(stringValue);
if (!(preference instanceof CheckBoxPreference)) {
if (preference instanceof EditTextPreference) {
@SunshineSyncAdapter.LocationStatus int status = Utility.getLocationStatus(this);
switch (status) {
case SunshineSyncAdapter.LOCATION_STATUS_OK:
break;
case SunshineSyncAdapter.LOCATION_STATUS_INVALID:
stringValue = String.format(getString(R.string.pref_location_error_description), stringValue);
break;
default:
stringValue = String.format(getString(R.string.pref_location_unknown_description), stringValue);
break;
}
}
preference.setSummary(stringValue);
}

}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ public void onSaveInstanceState(Bundle outState) {
public void setUseTodayLayout(boolean useTodayLayout) {
mUseTodayLayout = useTodayLayout;
if (mForecastAdapter != null) {
mForecastAdapter.setmUseTodayLayout(mUseTodayLayout);
mForecastAdapter.setUseTodayLayout(mUseTodayLayout);
}
}

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mForecastAdapter = new ForecastAdapter(getActivity(), null, 0);
mForecastAdapter.setmUseTodayLayout(mUseTodayLayout);
mForecastAdapter.setUseTodayLayout(mUseTodayLayout);
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
View emptyView = rootView.findViewById(R.id.empty_view);
mListView = (ListView) rootView.findViewById(R.id.listview_forecast);
Expand Down Expand Up @@ -135,7 +135,7 @@ public void onItemClick(AdapterView adapterView, View view, int position, long l
mPosition = savedInstanceState.getInt(SELECTED_KEY);
}

mForecastAdapter.setmUseTodayLayout(mUseTodayLayout);
mForecastAdapter.setUseTodayLayout(mUseTodayLayout);

return rootView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private String formatHighLows(double high, double low) {
return highLowStr;
}

public void setmUseTodayLayout(boolean useTodayLayout){
public void setUseTodayLayout(boolean useTodayLayout){
mUseTodayLayout = useTodayLayout;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.calgen.prodek.sunshine_v2.customView;

import android.app.Dialog;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.widget.Button;
import android.widget.EditText;

import com.calgen.prodek.sunshine_v2.R;

/**
* Created by Gurupad Mamadapur on 11/8/2016.
*/

public class LocationEditText extends EditTextPreference {

private final int DEFAULT_MINIMUM_LOCATION_LENGTH = 3;
private final String TAG = EditTextPreference.class.getSimpleName();
public int minLength;

public LocationEditText(Context context, AttributeSet attrs) {
super(context, attrs);

TypedArray array = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.LocationEditText,
0, 0);

try {
minLength = array.getInteger(R.styleable.LocationEditText_minLength, DEFAULT_MINIMUM_LOCATION_LENGTH);
} finally {
array.recycle();
}
}

@Override
protected void showDialog(Bundle state) {
super.showDialog(state);
EditText editText = getEditText();
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override
public void afterTextChanged(Editable s) {
Dialog dialog= getDialog();
if (dialog instanceof AlertDialog) {
AlertDialog alertDialog = (AlertDialog) dialog;
Button positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
positiveButton.setEnabled(s.length() > minLength);
}
}
});
}
}
3 changes: 2 additions & 1 deletion app/src/main/res/layout/fragment_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:gravity="start"
android:orientation="vertical">

<TextView
Expand Down Expand Up @@ -97,6 +97,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="0dp"
android:layout_marginEnd="0dp"
android:layout_marginTop="16dp"
android:orientation="vertical">

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/fragment_detail_wide.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<LinearLayout
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_width="wrap_content"
android:orientation="vertical">

Expand All @@ -54,6 +55,8 @@
android:id="@+id/detail_low_textview"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="16dp"

android:layout_width="wrap_content"
android:textColor="@color/grey_700"
android:textSize="48sp" />
Expand Down Expand Up @@ -88,6 +91,8 @@
android:gravity="center_horizontal"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"

android:layout_width="wrap_content"
android:orientation="vertical">

Expand Down
44 changes: 24 additions & 20 deletions app/src/main/res/layout/list_tem_forecast_today.xml
Original file line number Diff line number Diff line change
@@ -1,53 +1,57 @@
<!-- Layout for weather forecast list item for today -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:background="@drawable/today_touch_selector">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/today_touch_selector"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="horizontal">

<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="7"
android:layout_marginTop="16dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="60dp"
android:layout_marginStart="60dp"
android:layout_marginTop="16dp"
android:layout_weight="7"
android:orientation="vertical">

<TextView
android:id="@+id/list_item_date_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceLarge"
android:fontFamily="sans-serif-condensed"
android:textColor="@color/white" />
android:textAppearance="?android:textAppearanceLarge"
android:textColor="@color/white"/>

<TextView
android:id="@+id/list_item_high_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="72sp"
android:fontFamily="sans-serif-light"
android:textColor="@color/white" />
android:textColor="@color/white"
android:textSize="72sp"/>

<TextView
android:id="@+id/list_item_low_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"

android:textColor="@color/white"
android:textSize="36sp"
android:layout_marginLeft="8dp"/>
android:textSize="36sp"/>
</LinearLayout>

<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:orientation="vertical"
android:gravity="center_horizontal|bottom">
android:layout_marginEnd="16dp"
android:layout_weight="5"
android:gravity="center_horizontal|bottom"
android:orientation="vertical">

<ImageView
android:id="@+id/list_item_icon"
Expand All @@ -59,8 +63,8 @@
android:id="@+id/list_item_forecast_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:layout_gravity="center_horizontal"
android:fontFamily="sans-serif-condensed"
android:textAppearance="?android:textAppearanceLarge"
android:textColor="@color/white"/>
</LinearLayout>
Expand Down
26 changes: 15 additions & 11 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
<resources>
<declare-styleable name="CompassView">
<attr name="direction" format="enum">
<enum name="n" value="0" />
<enum name="ne" value="1" />
<enum name="e" value="2" />
<enum name="se" value="3" />
<enum name="s" value="4" />
<enum name="sw" value="5" />
<enum name="w" value="6" />
<enum name="nw" value="7" />
<enum name="n" value="0"/>
<enum name="ne" value="1"/>
<enum name="e" value="2"/>
<enum name="se" value="3"/>
<enum name="s" value="4"/>
<enum name="sw" value="5"/>
<enum name="w" value="6"/>
<enum name="nw" value="7"/>
</attr>
<attr name="speed" format="enum">
<enum name="low" value="0" />
<enum name="moderate" value="1" />
<enum name="high" value="2" />
<enum name="low" value="0"/>
<enum name="moderate" value="1"/>
<enum name="high" value="2"/>
</attr>
</declare-styleable>
<declare-styleable name="LocationEditText">
<attr name="minLength" format="integer"/>
</declare-styleable>

</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,8 @@
<string name="empty_forecast_list_server_error">No weather information available. The server is not returning valid data. Please check for an updated version of Sunshine.</string>
<string name="empty_forecast_list_invalid_location">No weather information available. The location in settings is not recognized by the weather server.</string>

<!-- Strings used when displaying the state of the Location in settings -->
<string name="pref_location_error_description">Invalid Location (<xliff:g id="location_setting">%1$s</xliff:g>)"</string>
<string name="pref_location_unknown_description">Validating Location… (<xliff:g id="location_setting">%1$s</xliff:g>)"</string>

</resources>
12 changes: 8 additions & 4 deletions app/src/main/res/xml/pref_general.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="com.calgen.prodek.sunshine_v2.customView.LocationEditText"
android:layout_width="match_parent"
android:layout_height="match_parent">

<EditTextPreference
<com.calgen.prodek.sunshine_v2.customView.LocationEditText
android:defaultValue="@string/pref_location_default"
android:inputType="text"
android:key="@string/pref_location_key"
android:singleLine="true"
android:title="@string/pref_location_label" />
android:title="@string/pref_location_label"
custom:minLength="3"
/>

<ListPreference
android:defaultValue="@string/pref_temperature_default"
android:entries="@array/pref_unit_titles"
android:entryValues="@array/pref_unit_values"
android:key="@string/pref_temperature_key"
android:title="@string/pref_temperature_label" />
android:title="@string/pref_temperature_label"/>

<CheckBoxPreference
android:defaultValue="@string/pref_notification_default"
Expand Down

0 comments on commit a4cebd7

Please sign in to comment.