Skip to content

Commit 9389505

Browse files
committed
Corner gestures
1 parent fa89be4 commit 9389505

26 files changed

+351
-20
lines changed

project/app/src/main/java/com/achep/acdisplay/Config.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ public final class Config extends ConfigBase {
104104
public static final int PRIVACY_HIDE_CONTENT_MASK = 1;
105105
public static final int PRIVACY_HIDE_ACTIONS_MASK = 2;
106106
public static final String KEY_DOUBLE_TAP_TO_SLEEP = "double_tap_to_sleep";
107+
public static final String KEY_CORNER_ACTION_LEFT_TOP = "corner_action_left_top";
108+
public static final String KEY_CORNER_ACTION_RIGHT_TOP = "corner_action_right_top";
109+
public static final String KEY_CORNER_ACTION_LEFT_BOTTOM = "corner_action_left_bottom";
110+
public static final String KEY_CORNER_ACTION_RIGHT_BOTTOM = "corner_action_right_bottom";
111+
/**
112+
* The default corner's action. Simply unlocks the device.
113+
*/
114+
public static final int CORNER_UNLOCK = 0;
115+
/**
116+
* Launches a camera.
117+
*/
118+
public static final int CORNER_LAUNCH_CAMERA = 1;
119+
/**
120+
* Launches a dialer.
121+
*/
122+
public static final int CORNER_LAUNCH_DIALER = 2;
107123

108124
// development
109125
public static final String KEY_DEV_SENSORS_DUMP = "dev_sensors_dump";
@@ -147,6 +163,10 @@ public final class Config extends ConfigBase {
147163
private int mUiCircleColorInner;
148164
private int mUiCircleColorOuter;
149165
private int mPrivacyMode;
166+
private int mCornerActionLeftTop;
167+
private int mCornerActionRightTop;
168+
private int mCornerActionLeftBottom;
169+
private int mCornerActionRightBottom;
150170
private boolean mInactiveTimeEnabled;
151171
private boolean mUiFullScreen;
152172
private boolean mUiOverrideFonts;
@@ -324,6 +344,18 @@ protected void onCreateMap(@NonNull Map<String, Option> map) {
324344
map.put(KEY_DOUBLE_TAP_TO_SLEEP, new ConfigBase.Option(
325345
"mDoubleTapToSleep", null, null, boolean.class)
326346
.setDefaultRes(R.bool.config_default_double_tap_to_sleep));
347+
map.put(KEY_CORNER_ACTION_LEFT_TOP, new ConfigBase.Option(
348+
"mCornerActionLeftTop", null, null, int.class)
349+
.setDefaultRes(R.integer.config_default_corner_left_top));
350+
map.put(KEY_CORNER_ACTION_RIGHT_TOP, new ConfigBase.Option(
351+
"mCornerActionRightTop", null, null, int.class)
352+
.setDefaultRes(R.integer.config_default_corner_right_top));
353+
map.put(KEY_CORNER_ACTION_LEFT_BOTTOM, new ConfigBase.Option(
354+
"mCornerActionLeftBottom", null, null, int.class)
355+
.setDefaultRes(R.integer.config_default_corner_left_bottom));
356+
map.put(KEY_CORNER_ACTION_RIGHT_BOTTOM, new ConfigBase.Option(
357+
"mCornerActionRightBottom", null, null, int.class)
358+
.setDefaultRes(R.integer.config_default_corner_right_bottom));
327359

328360
// triggers
329361
map.put(KEY_TRIG_DONATION_ASKED, new ConfigBase.Option(
@@ -517,6 +549,38 @@ public int getCustomWidgetHeightDp() {
517549
return mUiCustomWidgetHeightDp;
518550
}
519551

552+
/**
553+
* @return an action of the left top corner of the screen.
554+
* @see com.achep.acdisplay.ui.CornerHelper
555+
*/
556+
public int getCornerActionLeftTop() {
557+
return mCornerActionLeftTop;
558+
}
559+
560+
/**
561+
* @return an action of the right top corner of the screen.
562+
* @see com.achep.acdisplay.ui.CornerHelper
563+
*/
564+
public int getCornerActionRightTop() {
565+
return mCornerActionRightTop;
566+
}
567+
568+
/**
569+
* @return an action of the left bottom corner of the screen.
570+
* @see com.achep.acdisplay.ui.CornerHelper
571+
*/
572+
public int getCornerActionLeftBottom() {
573+
return mCornerActionLeftBottom;
574+
}
575+
576+
/**
577+
* @return an action of the right bottom corner of the screen.
578+
* @see com.achep.acdisplay.ui.CornerHelper
579+
*/
580+
public int getCornerActionRightBottom() {
581+
return mCornerActionRightBottom;
582+
}
583+
520584
/**
521585
* @return the size (or height only) of collapsed views in pixels.
522586
* @see #getIconSize(String)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (C) 2015 AChep@xda <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version 2
7+
* of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301, USA.
18+
*/
19+
package com.achep.acdisplay.ui;
20+
21+
import android.content.Context;
22+
import android.content.Intent;
23+
import android.net.Uri;
24+
import android.provider.MediaStore;
25+
import android.support.annotation.DrawableRes;
26+
import android.support.annotation.NonNull;
27+
import android.util.Log;
28+
29+
import com.achep.acdisplay.Config;
30+
import com.achep.acdisplay.R;
31+
32+
/**
33+
* Created by Artem Chepurnoy on 04.05.2015.
34+
*/
35+
public class CornerHelper {
36+
37+
private static final String TAG = "CornerHelper";
38+
39+
private static final int[] ICON_IDS = {
40+
R.drawable.ic_corner_unlock_white,
41+
R.drawable.ic_corner_launch_photo_camera_white,
42+
R.drawable.ic_corner_launch_dialer_white,
43+
};
44+
45+
/**
46+
* @return the icon's resource of the specific action.
47+
*/
48+
@DrawableRes
49+
public static int getIconResource(int actionId) {
50+
return ICON_IDS[actionId];
51+
}
52+
53+
/**
54+
* Performs the specific corner-action.
55+
*/
56+
public static void perform(@NonNull Context context, int actionId) {
57+
switch (actionId) {
58+
case Config.CORNER_UNLOCK:
59+
// Do nothing special.
60+
break;
61+
case Config.CORNER_LAUNCH_CAMERA:
62+
try {
63+
Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
64+
context.startActivity(intent);
65+
} catch (Exception e) {
66+
Log.i(TAG, "Unable to launch a camera.");
67+
e.printStackTrace();
68+
}
69+
break;
70+
case Config.CORNER_LAUNCH_DIALER:
71+
try {
72+
Intent intent = new Intent(Intent.ACTION_DIAL);
73+
intent.setData(Uri.parse("tel:")); // TODO: Check if works on all devices.
74+
context.startActivity(intent);
75+
} catch (Exception e) {
76+
Log.i(TAG, "Unable to launch a dialer.");
77+
e.printStackTrace();
78+
}
79+
break;
80+
default:
81+
throw new IllegalArgumentException();
82+
}
83+
}
84+
85+
}

project/app/src/main/java/com/achep/acdisplay/ui/fragments/AcDisplayFragment.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import com.achep.acdisplay.notifications.OpenNotification;
6565
import com.achep.acdisplay.services.media.MediaController2;
6666
import com.achep.acdisplay.services.media.Metadata;
67+
import com.achep.acdisplay.ui.CornerHelper;
6768
import com.achep.acdisplay.ui.DynamicBackground;
6869
import com.achep.acdisplay.ui.activities.AcDisplayActivity;
6970
import com.achep.acdisplay.ui.components.ClockWidget;
@@ -472,7 +473,7 @@ public void requestTimeoutRestart(@NonNull Widget widget) {
472473
//-- TOUCH HANDLING -------------------------------------------------------
473474

474475
@Override
475-
public void onCircleEvent(float radius, float ratio, int event) {
476+
public void onCircleEvent(float radius, float ratio, int event, final int actionId) {
476477
switch (event) {
477478
case CircleView.ACTION_START:
478479
if (mHasPinnedWidget) {
@@ -489,7 +490,14 @@ public void onCircleEvent(float radius, float ratio, int event) {
489490
mActivityAcd.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
490491
break;
491492
case CircleView.ACTION_UNLOCK:
492-
mActivityAcd.unlock(null);
493+
mActivityAcd.unlock(new Runnable() {
494+
@Override
495+
public void run() {
496+
Context context = getActivity();
497+
assert context != null;
498+
CornerHelper.perform(context, actionId);
499+
}
500+
});
493501
case CircleView.ACTION_CANCELED:
494502
// Clear the pinned widget on short tap in emulator
495503
// (and probably something in real life too).

project/app/src/main/java/com/achep/acdisplay/ui/fragments/settings/MoreSettings.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package com.achep.acdisplay.ui.fragments.settings;
2020

2121
import android.os.Bundle;
22+
import android.preference.ListPreference;
2223
import android.preference.Preference;
2324
import android.preference.PreferenceGroup;
2425
import android.support.annotation.NonNull;
@@ -39,6 +40,20 @@ public class MoreSettings extends BaseSettings implements
3940
ConfigBase.OnConfigChangedListener,
4041
Preference.OnPreferenceClickListener {
4142

43+
private final ListPreferenceSetter mListPreferenceCornerActionSetter =
44+
new ListPreferenceSetter() {
45+
46+
@Override
47+
public void updateSummary(@NonNull Preference preference,
48+
@NonNull Config.Option option,
49+
@NonNull Object value) {
50+
int pos = (int) value;
51+
ListPreference cbp = (ListPreference) preference;
52+
cbp.setSummary(cbp.getEntries()[pos]);
53+
}
54+
55+
};
56+
4257
private Preference mInactiveHoursPreference;
4358
private Preference mTimeoutPreference;
4459
private Preference mDataRestoreDefaultsPreference;
@@ -57,6 +72,10 @@ public void onCreate(Bundle savedInstanceState) {
5772
syncPreference(Config.KEY_DOUBLE_TAP_TO_SLEEP);
5873
syncPreference(Config.KEY_FEEL_WIDGET_PINNABLE);
5974
syncPreference(Config.KEY_FEEL_WIDGET_READABLE);
75+
syncPreference(Config.KEY_CORNER_ACTION_LEFT_TOP, mListPreferenceCornerActionSetter);
76+
syncPreference(Config.KEY_CORNER_ACTION_LEFT_BOTTOM, mListPreferenceCornerActionSetter);
77+
syncPreference(Config.KEY_CORNER_ACTION_RIGHT_TOP, mListPreferenceCornerActionSetter);
78+
syncPreference(Config.KEY_CORNER_ACTION_RIGHT_BOTTOM, mListPreferenceCornerActionSetter);
6079

6180
mInactiveHoursPreference = findPreference("inactive_hours");
6281
mTimeoutPreference = findPreference("timeout");

0 commit comments

Comments
 (0)