Skip to content

Commit 8f7f73a

Browse files
committed
Add a PreferenceActivity. Also remove Google repository
1 parent 2064aa7 commit 8f7f73a

File tree

20 files changed

+393
-38
lines changed

20 files changed

+393
-38
lines changed

app/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ android {
66
}
77
}
88
compileSdkVersion 25
9-
buildToolsVersion "25.0.2"
9+
buildToolsVersion "25.0.3"
1010
defaultConfig {
1111
applicationId "com.fake.android.torchlight"
1212
minSdkVersion 16
@@ -39,6 +39,8 @@ android {
3939

4040
dependencies {
4141
compile fileTree(include: ['*.jar'], dir: 'libs')
42-
compile 'com.android.support:appcompat-v7:25.3.1'
43-
compile 'com.android.support:design:25.3.1'
42+
compile 'com.android.support:appcompat-v7:25.1.0'
43+
compile 'com.android.support:design:25.1.0'
44+
compile 'com.android.support:support-v4:25.1.0'
45+
compile 'com.android.support:support-vector-drawable:25.1.0'
4446
}

app/src/main/AndroidManifest.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@
5757
android:name="android.appwidget.provider"
5858
android:resource="@xml/torchlight_widget_info" />
5959
</receiver>
60+
61+
<activity
62+
android:name=".SettingsActivity"
63+
android:label="@string/action_settings"
64+
android:parentActivityName=".MainActivity">
65+
<meta-data
66+
android:name="android.support.PARENT_ACTIVITY"
67+
android:value="com.fake.android.torchlight.MainActivity" />
68+
</activity>
6069
</application>
6170

6271
</manifest>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package com.fake.android.torchlight;
2+
3+
import android.content.res.Configuration;
4+
import android.os.Bundle;
5+
import android.preference.PreferenceActivity;
6+
import android.support.annotation.LayoutRes;
7+
import android.support.annotation.NonNull;
8+
import android.support.annotation.Nullable;
9+
import android.support.v7.app.ActionBar;
10+
import android.support.v7.app.AppCompatDelegate;
11+
import android.support.v7.widget.Toolbar;
12+
import android.view.MenuInflater;
13+
import android.view.View;
14+
import android.view.ViewGroup;
15+
16+
/**
17+
* A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
18+
* to be used with AppCompat.
19+
*/
20+
@SuppressWarnings({"WeakerAccess", "unused"})
21+
public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
22+
23+
private AppCompatDelegate mDelegate;
24+
25+
@Override
26+
protected void onCreate(Bundle savedInstanceState) {
27+
getDelegate().installViewFactory();
28+
getDelegate().onCreate(savedInstanceState);
29+
super.onCreate(savedInstanceState);
30+
}
31+
32+
@Override
33+
protected void onPostCreate(Bundle savedInstanceState) {
34+
super.onPostCreate(savedInstanceState);
35+
getDelegate().onPostCreate(savedInstanceState);
36+
}
37+
38+
public ActionBar getSupportActionBar() {
39+
return getDelegate().getSupportActionBar();
40+
}
41+
42+
public void setSupportActionBar(@Nullable Toolbar toolbar) {
43+
getDelegate().setSupportActionBar(toolbar);
44+
}
45+
46+
@NonNull
47+
@Override
48+
public MenuInflater getMenuInflater() {
49+
return getDelegate().getMenuInflater();
50+
}
51+
52+
@Override
53+
public void setContentView(@LayoutRes int layoutResID) {
54+
getDelegate().setContentView(layoutResID);
55+
}
56+
57+
@Override
58+
public void setContentView(View view) {
59+
getDelegate().setContentView(view);
60+
}
61+
62+
@Override
63+
public void setContentView(View view, ViewGroup.LayoutParams params) {
64+
getDelegate().setContentView(view, params);
65+
}
66+
67+
@Override
68+
public void addContentView(View view, ViewGroup.LayoutParams params) {
69+
getDelegate().addContentView(view, params);
70+
}
71+
72+
@Override
73+
protected void onPostResume() {
74+
super.onPostResume();
75+
getDelegate().onPostResume();
76+
}
77+
78+
@Override
79+
protected void onTitleChanged(CharSequence title, int color) {
80+
super.onTitleChanged(title, color);
81+
getDelegate().setTitle(title);
82+
}
83+
84+
@Override
85+
public void onConfigurationChanged(Configuration newConfig) {
86+
super.onConfigurationChanged(newConfig);
87+
getDelegate().onConfigurationChanged(newConfig);
88+
}
89+
90+
@Override
91+
protected void onStop() {
92+
super.onStop();
93+
getDelegate().onStop();
94+
}
95+
96+
@Override
97+
protected void onDestroy() {
98+
super.onDestroy();
99+
getDelegate().onDestroy();
100+
}
101+
102+
public void invalidateOptionsMenu() {
103+
getDelegate().invalidateOptionsMenu();
104+
}
105+
106+
private AppCompatDelegate getDelegate() {
107+
if (mDelegate == null) {
108+
mDelegate = AppCompatDelegate.create(this, null);
109+
}
110+
return mDelegate;
111+
}
112+
}

app/src/main/java/com/fake/android/torchlight/MainActivity.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.Manifest;
44
import android.content.Intent;
55
import android.content.pm.PackageManager;
6+
import android.net.Uri;
67
import android.os.Bundle;
78
import android.support.annotation.NonNull;
89
import android.support.design.widget.FloatingActionButton;
@@ -22,6 +23,8 @@
2223
import com.fake.android.torchlight.camera.Camera;
2324
import com.fake.android.torchlight.camera.CameraControl;
2425

26+
import java.io.File;
27+
2528
public class MainActivity extends AppCompatActivity
2629
implements NavigationView.OnNavigationItemSelectedListener {
2730
@SuppressWarnings("FieldCanBeLocal")
@@ -36,7 +39,6 @@ protected void onDestroy() {
3639
camera = null;
3740
}
3841

39-
//@TargetApi(23)
4042
private void requestPerm() {
4143
if (ContextCompat.checkSelfPermission(this,
4244
Manifest.permission.CAMERA)
@@ -49,7 +51,7 @@ private void requestPerm() {
4951
new String[]{Manifest.permission.CAMERA},
5052
MY_PERMISSIONS_REQUEST_CAMERA);
5153

52-
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
54+
// MY_PERMISSIONS_REQUEST_CAMERA is an
5355
// app-defined int constant. The callback method gets the
5456
// result of the request.
5557

@@ -81,6 +83,10 @@ public void onClick(View view) {
8183
requestPerm();
8284
camera.set(!camera.get());
8385
}
86+
if (!CameraControl.hasFlash()) {
87+
Intent intent = new Intent(MainActivity.this, FlashActivity.class);
88+
startActivity(intent);
89+
}
8490
updateImageButton();
8591
}
8692
});
@@ -97,15 +103,10 @@ public void onClick(View view) {
97103
}
98104

99105
private void updateImageButton() {
100-
if (CameraControl.hasFlash()) {
101-
if (camera.get()) {
102-
fab.setImageResource(R.drawable.ic_sunny_white);
103-
} else {
104-
fab.setImageResource(R.drawable.ic_sunny_black);
105-
}
106+
if (camera.get()) {
107+
fab.setImageResource(R.drawable.ic_sunny_white);
106108
} else {
107-
Intent intent = new Intent(MainActivity.this, FlashActivity.class);
108-
startActivity(intent);
109+
fab.setImageResource(R.drawable.ic_sunny_black);
109110
}
110111
}
111112

@@ -135,6 +136,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
135136

136137
//noinspection SimplifiableIfStatement
137138
if (id == R.id.action_settings) {
139+
Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
140+
startActivity(intent);
138141
return true;
139142
}
140143

@@ -148,9 +151,10 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
148151
int id = item.getItemId();
149152

150153
if (id == R.id.nav_manage) {
151-
154+
Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
155+
startActivity(intent);
152156
} else if (id == R.id.nav_share) {
153-
157+
Intent intent = new Intent("", Uri.fromFile(new File(MainActivity.this.getApplicationInfo().name)));
154158
} else if (id == R.id.nav_send) {
155159

156160
}

0 commit comments

Comments
 (0)