1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 03:11:30 +00:00

Added missing files for previous commit

This commit is contained in:
Felix Ableitner 2016-09-07 03:05:45 +02:00
parent d464010ee5
commit aefec10f84
2 changed files with 148 additions and 0 deletions

View file

@ -0,0 +1,104 @@
package com.nutomic.syncthingandroid.activities;
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.nutomic.syncthingandroid.R;
public class FirstStartActivity extends Activity implements Button.OnClickListener {
private static final String TAG = "FirstStartActivity";
private static final int REQUEST_WRITE_STORAGE = 142;
private SharedPreferences mPreferences;
/**
* Handles activity behaviour depending on {@link #isFirstStart()} and {@link #haveStoragePermission()}.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first_start);
mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
Button cont = (Button) findViewById(R.id.cont);
cont.setOnClickListener(this);
if (!isFirstStart()) {
if (haveStoragePermission()) {
startApp();
}
else {
requestStoragePermission();
}
}
}
private boolean isFirstStart() {
return mPreferences.getBoolean("first_start", true);
}
private void startApp() {
boolean isFirstStart = isFirstStart();
if (isFirstStart) {
mPreferences.edit().putBoolean("first_start", false).apply();
}
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(MainActivity.EXTRA_FIRST_START, isFirstStart);
startActivity(intent);
finish();
}
private boolean haveStoragePermission() {
int permissionState = ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
return permissionState == PackageManager.PERMISSION_GRANTED;
}
private void requestStoragePermission() {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
REQUEST_WRITE_STORAGE);
}
@Override
public void onClick(View v) {
if (!haveStoragePermission()) {
requestStoragePermission();
}
else {
startApp();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
switch (requestCode) {
case REQUEST_WRITE_STORAGE:
if (grantResults.length == 0 ||
grantResults[0] != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, R.string.toast_write_storage_permission_required,
Toast.LENGTH_LONG).show();
} else {
startApp();
}
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}

View file

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context="com.nutomic.syncthingandroid.activities.FirstStartActivity">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/welcome_title"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textColor="@color/primary_dark"
android:textSize="30sp"
android:layout_margin="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/welcome_text"
android:layout_below="@id/title"
android:textSize="16sp"
android:lineSpacingExtra="5sp"
android:layout_marginStart="30dp"
android:layout_marginLeft="30dp"
android:layout_marginEnd="30dp"
android:layout_marginRight="30dp" />
<Button
android:id="@+id/cont"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cont"
android:background="?android:selectableItemBackground"
android:textColor="@color/accent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>