Skip to content

Commit

Permalink
Allow switching button position
Browse files Browse the repository at this point in the history
Top (default) or bottom

Change-Id: I27196fe3847b73ca4b0ab17c87d890de60fe2a0f
  • Loading branch information
maxwen authored and Alex Cruz committed Jan 14, 2015
1 parent 69d6c78 commit 9144666
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 8 deletions.
26 changes: 23 additions & 3 deletions res/layout/recents_list_horizontal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/button_list_container"
android:id="@+id/button_list_container_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:orientation="vertical" >
<HorizontalScrollView
android:id="@+id/button_list"
android:id="@+id/button_list_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
<LinearLayout
android:id="@+id/button_list_items"
android:id="@+id/button_list_items_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
Expand Down Expand Up @@ -83,4 +84,23 @@
android:stretchMode="spacingWidthUniform"
android:visibility="gone" />
</RelativeLayout>
<LinearLayout
android:id="@+id/button_list_container_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:orientation="vertical" >
<HorizontalScrollView
android:id="@+id/button_list_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
<LinearLayout
android:id="@+id/button_list_items_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</LinearLayout>
8 changes: 8 additions & 0 deletions res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@
<item>@string/kill_all_apps</item>
<item>@string/kill_other_apps</item>
</string-array>
<string-array name="button_pos_entries" translatable="false">
<item>@string/button_pos_top</item>
<item>@string/button_pos_bottom</item>
</string-array>
<string-array name="button_pos_values" translatable="false">
<item>0</item>
<item>1</item>
</string-array>
</resources>
3 changes: 3 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,7 @@
<string name="flat_style_summary">Use solid background for overlay view</string>
<string name="flat_style_title">Flat style</string>
<string name="open_favorite_help">Open/close favorites view</string>
<string name="button_pos_title">Button position</string>
<string name="button_pos_top">Top</string>
<string name="button_pos_bottom">Bottom</string>
</resources>
6 changes: 6 additions & 0 deletions res/xml/recents_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
android:key="button_config"
android:summary="@string/buttons_summary"
android:title="@string/buttons_title" />
<ListPreference
android:entries="@array/button_pos_entries"
android:entryValues="@array/button_pos_values"
android:key="button_pos"
android:summary="@string/button_pos_top"
android:title="@string/button_pos_title" />
</PreferenceCategory>
<PreferenceCategory
android:key="category_drag_handle"
Expand Down
14 changes: 14 additions & 0 deletions src/org/omnirom/omniswitch/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class SettingsActivity extends PreferenceActivity implements
public static final String PREF_SPEED_SWITCHER_BUTTON_DEFAULT_NEW = "0:1,1:1,2:1,3:1,4:1";
public static final String PREF_SPEED_SWITCHER_ITEMS = "speed_switch_items";
public static final String PREF_FLAT_STYLE = "flat_style";
public static final String PREF_BUTTON_POS = "button_pos";

public static int BUTTON_KILL_ALL = 0;
public static int BUTTON_KILL_OTHER = 1;
Expand Down Expand Up @@ -120,6 +121,7 @@ public class SettingsActivity extends PreferenceActivity implements
private Drawable[] mSpeedSwitchButtonImages;
private String mSpeedSwitchButtons;
private NumberPickerPreference mSpeedSwitchItems;
private ListPreference mButtonPos;

@Override
public void onPause() {
Expand Down Expand Up @@ -178,6 +180,12 @@ public void onCreate(Bundle savedInstanceState) {
mSpeedSwitchItems.setMaxValue(20);
mSpeedSwitchButtonConfig = (Preference) findPreference(PREF_SPEED_SWITCHER_BUTTON_CONFIG);
mSpeedSwitchButtons = mPrefs.getString(PREF_SPEED_SWITCHER_BUTTON_NEW, PREF_SPEED_SWITCHER_BUTTON_DEFAULT_NEW);
mButtonPos = (ListPreference) findPreference(PREF_BUTTON_POS);
mButtonPos.setOnPreferenceChangeListener(this);
idx = mButtonPos.findIndexOfValue(mPrefs.getString(PREF_BUTTON_POS,
mButtonPos.getEntryValues()[0].toString()));
mButtonPos.setValueIndex(idx);
mButtonPos.setSummary(mButtonPos.getEntries()[idx]);
initButtons();

mPrefsListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
Expand Down Expand Up @@ -265,6 +273,12 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
mGravity.setSummary(mGravity.getEntries()[idx]);
mGravity.setValueIndex(idx);
return true;
} else if (preference == mButtonPos) {
String value = (String) newValue;
int idx = mButtonPos.findIndexOfValue(value);
mButtonPos.setSummary(mButtonPos.getEntries()[idx]);
mButtonPos.setValueIndex(idx);
return true;
}

return false;
Expand Down
3 changes: 3 additions & 0 deletions src/org/omnirom/omniswitch/SwitchConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class SwitchConfiguration {
public boolean mFlatStyle = true;
public int mHorizontalDividerWidth;
public float mLabelFontSize;
public int mButtonPos = 0; // 0 = top 1 = bottom

public static SwitchConfiguration mInstance;
private WindowManager mWindowManager;
Expand Down Expand Up @@ -155,6 +156,8 @@ public void updatePrefs(SharedPreferences prefs, String key) {
SettingsActivity.PREF_SPEED_SWITCHER_BUTTON_DEFAULT_NEW), SettingsActivity.PREF_SPEED_SWITCHER_BUTTON_DEFAULT_NEW);
mLimitItemsX = prefs.getInt(SettingsActivity.PREF_SPEED_SWITCHER_ITEMS, 10);
mFlatStyle = prefs.getBoolean(SettingsActivity.PREF_FLAT_STYLE, true);
String buttonPos = prefs.getString(SettingsActivity.PREF_BUTTON_POS, "0");
mButtonPos = Integer.valueOf(buttonPos);
}

// includes rotation
Expand Down
14 changes: 9 additions & 5 deletions src/org/omnirom/omniswitch/ui/SwitchLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,6 @@ private synchronized void createView() {
mNoRecentApps = (TextView) mView
.findViewById(R.id.no_recent_apps);

mButtonList = (HorizontalScrollView) mView.findViewById(R.id.button_list);
mButtonList.setHorizontalScrollBarEnabled(false);
mButtonListItems = (LinearLayout) mView.findViewById(R.id.button_list_items);
mButtonListContainer = (LinearLayout) mView.findViewById(R.id.button_list_container);

mRecentListHorizontal
.setOnItemClickListener(new OnItemClickListener() {
@Override
Expand Down Expand Up @@ -581,6 +576,15 @@ private synchronized void updateRecentsAppsList(boolean force){
}

private synchronized void initView(){
if (mButtonListContainer != null) {
mButtonListContainer.setVisibility(View.GONE);
}
mButtonList = (HorizontalScrollView) mView.findViewById(mConfiguration.mButtonPos == 0 ? R.id.button_list_top : R.id.button_list_bottom);
mButtonList.setHorizontalScrollBarEnabled(false);
mButtonListItems = (LinearLayout) mView.findViewById(mConfiguration.mButtonPos == 0 ? R.id.button_list_items_top : R.id.button_list_items_bottom);
mButtonListContainer = (LinearLayout) mView.findViewById(mConfiguration.mButtonPos == 0 ? R.id.button_list_container_top : R.id.button_list_container_bottom);
mButtonListContainer.setVisibility(View.VISIBLE);

updateStyle();

if (mConfiguration.mFlatStyle) {
Expand Down

0 comments on commit 9144666

Please sign in to comment.