Commit 36fa2f0c authored by Mathias Stanger's avatar Mathias Stanger

Morph-Buttons für Clicki-Bunti-UI hinzugefügt.

Berechtigung "READ_EXTERNAL_STORAGE" wird nun zur Laufzeit vom Benutzer abgefragt.
parent 53fee344
......@@ -18,12 +18,17 @@ android {
}
}
}
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.jcraft:jsch:0.1.53'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.redmadrobot:chronos:1.0.5'
compile 'com.github.dmytrodanylyk:android-morphing-button:98a4986e56'
}
package de.matsta.yasc;
import android.Manifest;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
import de.matsta.yasc.fragments.ControlFragment;
public class FragmentContainerActivity extends AppCompatActivity {
private static final int PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -24,6 +31,44 @@ public class FragmentContainerActivity extends AppCompatActivity {
}
}
@Override
protected void onResume() {
super.onResume();
// Berechtigung zur Laufzeit erfragen
requestPermission();
}
private void requestPermission() {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
// Berechtigung vom Benutzer erbeten
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Yey, der allmächtige Benutzer hat mich erhört.
} else {
// Wir haben das Recht nicht erhalten. Das ist sehr sehr schade...
Toast.makeText(this, "Ich brauch das aber... :-(", Toast.LENGTH_LONG).show();
requestPermission();
}
return;
}
}
}
@Override
public void onBackPressed() {
// Haben wir einen BackStack-Eintrag (z.B. bei geöffneten Einstellungen), dann navigieren wir zuerst darin zurück.
......
......@@ -3,8 +3,11 @@ package de.matsta.yasc;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import com.dd.morphingbutton.MorphingButton;
import java.net.URISyntaxException;
public class Utils {
......@@ -27,4 +30,52 @@ public class Utils {
}
return null;
}
public static void morphToSuccess(final MorphingButton btnMorph) {
MorphingButton.Params circle = MorphingButton.Params.create()
.duration(500)
.cornerRadius(80)
.width(80)
.height(80)
.color(Color.GREEN)
.colorPressed(Color.YELLOW)
.icon(R.drawable.ic_check);
btnMorph.morph(circle);
}
public static void morphToButton(final MorphingButton btnMorph, final String caption) {
MorphingButton.Params square = MorphingButton.Params.create()
.duration(500)
.cornerRadius(2)
.width(400)
.height(70)
.color(Color.GRAY)
.colorPressed(Color.DKGRAY)
.text(caption);
btnMorph.morph(square);
}
public static void morphToFailure(final MorphingButton btnMorph, int duration) {
MorphingButton.Params circle = MorphingButton.Params.create()
.duration(duration)
.cornerRadius(80)
.width(80)
.height(80)
.color(Color.RED)
.colorPressed(Color.DKGRAY)
.icon(R.drawable.ic_fail);
btnMorph.morph(circle);
}
public static void morphToSquare(final MorphingButton btnMorph, int duration) {
MorphingButton.Params square = MorphingButton.Params.create()
.duration(duration)
.cornerRadius(2)
.width(200)
.height(70)
.color(Color.DKGRAY)
.colorPressed(Color.DKGRAY)
.text("...");
btnMorph.morph(square);
}
}
package de.matsta.yasc.fragments;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
......@@ -13,6 +16,7 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.dd.morphingbutton.MorphingButton;
import com.redmadrobot.chronos.gui.fragment.ChronosFragment;
import com.redmadrobot.chronos.gui.fragment.ChronosSupportFragment;
......@@ -21,12 +25,13 @@ import butterknife.ButterKnife;
import de.matsta.yasc.R;
import de.matsta.yasc.SharedPrefsTools;
import de.matsta.yasc.SshOperation;
import de.matsta.yasc.Utils;
public class ControlFragment extends ChronosFragment {
@Bind(R.id.btnBuzz)
Button mBtnBuzz;
MorphingButton mBtnBuzz;
@Bind(R.id.btnUnlock)
Button mBtnUnlock;
MorphingButton mBtnUnlock;
@Nullable
@Override
......@@ -38,6 +43,7 @@ public class ControlFragment extends ChronosFragment {
new View.OnClickListener() {
@Override
public void onClick(View v) {
Utils.morphToSquare(mBtnBuzz, 100);
executeRemote("buzz");
}
}
......@@ -46,10 +52,15 @@ public class ControlFragment extends ChronosFragment {
mBtnUnlock.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Utils.morphToSquare(mBtnUnlock, 100);
executeRemote("unlock");
}
});
Utils.morphToButton(mBtnBuzz, "Buzz");
Utils.morphToButton(mBtnUnlock, "Unlock");
return view;
}
......@@ -70,16 +81,19 @@ public class ControlFragment extends ChronosFragment {
public void onOperationFinished(final SshOperation.Result result) {
// TODO Rückgabe besser parsen
if (result.isSuccessful()) {
if(result.getOutput().contains("buzz executed")){
if (result.getOutput().contains("buzz executed")) {
// Buzz hat funktioniert.
Toast.makeText(getActivity(), "Buzz wurde ausgelöst", Toast.LENGTH_SHORT).show();
} else if(result.getOutput().contains("")) {
} else if (result.getOutput().contains("")) {
// Unlock hat funktioniert.
Toast.makeText(getActivity(), "Tür wurde entsperrt", Toast.LENGTH_SHORT).show();
} else {
// Fallback
Toast.makeText(getActivity(), result.getOutput(), Toast.LENGTH_LONG).show();
}
// Buttons wieder zurücksetzen
Utils.morphToButton(mBtnBuzz, "Buzz");
Utils.morphToButton(mBtnUnlock, "Unlock");
} else {
Toast.makeText(getActivity(), result.getErrorMessage(), Toast.LENGTH_LONG).show();
Log.d(this.getClass().getSimpleName(), result.getErrorMessage());
......
......@@ -3,18 +3,20 @@
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
<com.dd.morphingbutton.MorphingButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Buzz"
android:id="@+id/btnBuzz"
android:layout_gravity="center_horizontal" />
android:layout_gravity="center_horizontal"
android:layout_marginTop="80dp" />
<Button
<com.dd.morphingbutton.MorphingButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unlock"
android:id="@+id/btnUnlock"
android:layout_gravity="center_horizontal" />
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp" />
</LinearLayout>
\ No newline at end of file
......@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.android.tools.build:gradle:2.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment