Skip to content

Commit

Permalink
implemented feature to switch between 3 orientation modes (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb3rko committed Jul 10, 2020
1 parent 44c1ae9 commit 33e65f6
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 64 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
implementation 'com.amitshekhar.android:android-networking:1.0.2'
implementation 'com.getkeepsafe.taptargetview:taptargetview:1.13.0'
implementation 'com.github.GrenderG:Toasty:1.4.2'
implementation 'com.github.medyo:android-about-page:1.2.6'
implementation 'com.github.medyo:android-about-page:1.3'
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.google.firebase:firebase-analytics:17.4.3'
implementation 'com.google.firebase:firebase-core:17.4.3'
Expand Down
20 changes: 4 additions & 16 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,16 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize">
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Credits"
android:screenOrientation="portrait" >
</activity>
<activity android:name=".About" />
<activity android:name=".IconCredits" />
<activity
android:name=".PrivacyPolicy"
android:screenOrientation="portrait" >
</activity>
<activity android:name=".TermsOfUse"
android:screenOrientation="portrait" >
</activity>
<activity android:name=".EndUserConsent" />
<activity android:name=".EndUserConsent2" />
<activity android:name=".PrivacyPolicy" />
<activity android:name=".TermsOfUse" />

<meta-data
android:name="firebase_analytics_collection_enabled"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
package com.thegreek.niko.logviewer_for_openHAB;

import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.mikepenz.aboutlibraries.LibsBuilder;

import java.util.Objects;

import mehdi.sakout.aboutpage.AboutPage;
import mehdi.sakout.aboutpage.Element;

public class Credits extends AppCompatActivity {
public class About extends AppCompatActivity {

@Override
protected void onCreate(@NonNull Bundle savedInstanceState) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

SharedPreferences mySPR = this.getSharedPreferences("Safe", 0);
MainActivity.changeOrientation(Objects.requireNonNull(this), mySPR.getInt("orientation", 0));

View aboutPage = new AboutPage(this)
.isRTL(false)
.setImage(R.mipmap.ic_launcher_foreground)
.setDescription(getString(R.string.about_description))
.addItem(new Element().setTitle("Version " + BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + ")").setOnClickListener(new View.OnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.thegreek.niko.logviewer_for_openHAB;

import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.text.SpannableString;
Expand All @@ -13,11 +14,15 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import java.util.Objects;

public class IconCredits extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences mySPR = this.getSharedPreferences("Safe", 0);
MainActivity.changeOrientation(Objects.requireNonNull(this), mySPR.getInt("orientation", 0));
setContentView(R.layout.activity_icon_credits);

TextView[] textViews = new TextView[9];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,31 @@
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.app.ActivityCompat;

import com.androidnetworking.AndroidNetworking;
import com.androidnetworking.error.ANError;
import com.androidnetworking.interfaces.StringRequestListener;
import com.google.firebase.analytics.FirebaseAnalytics;

import es.dmoral.toasty.Toasty;
import java.util.Objects;

public class MainActivity extends AppCompatActivity {

static FirebaseAnalytics firebaseAnalytics;
private SharedPreferences mySPR;
private SharedPreferences.Editor editor;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
setContentView(R.layout.activity_main);

firebaseAnalytics = FirebaseAnalytics.getInstance(this);
mySPR = this.getSharedPreferences("Safe", 0);
SharedPreferences mySPR = this.getSharedPreferences("Safe", 0);
editor = mySPR.edit();
editor.apply();
Toasty.Config.getInstance().allowQueue(false).apply();
// Toasty.Config.getInstance().allowQueue(false).apply();
MainActivity.changeOrientation(Objects.requireNonNull(this), mySPR.getInt("orientation", 0));

getSupportFragmentManager().beginTransaction().replace(R.id.start, new MainFragment()).commit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -33,6 +34,7 @@ public class MainFragment extends Fragment {
private EditText port;
private ImageButton hostnameIPAddressEdit;
private ImageButton portEdit;
private ImageView settings;
private SharedPreferences mySPR;
private SharedPreferences.Editor editor;
private String hostnameIPAddressString;
Expand All @@ -42,7 +44,7 @@ public class MainFragment extends Fragment {
private int portInt;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.fragment_main, container, false);

hostnameIPAddress = v.findViewById(R.id.hostname_ip_address);
Expand All @@ -57,7 +59,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
TextView endUserConsent = v.findViewById(R.id.end_user_consent);
TextView credits_text = v.findViewById(R.id.credits);
TextView versionView = v.findViewById(R.id.version_view);
ImageView settings = v.findViewById(R.id.imageView);
settings = v.findViewById(R.id.imageView);

mySPR = v.getContext().getSharedPreferences("Safe", 0);
editor = mySPR.edit();
Expand All @@ -69,13 +71,31 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
settings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int newOrientation = mySPR.getInt("orientation", 0) == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT :
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
int newOrientation = 0;
String newOrientationName = "";

switch (mySPR.getInt("orientation", ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)) {
case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
newOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
newOrientationName = "portrait";
break;
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
newOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
newOrientationName = "auto";
settings.setImageResource(R.drawable.icon_auto_orientation);
break;
case ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED:
newOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
newOrientationName = "landscape";
default:
break;
}

editor.putInt("orientation", newOrientation);
editor.putBoolean("tempDisableStart", true).apply();
MainActivity.changeOrientation(Objects.requireNonNull(getActivity()), newOrientation);
editor.putInt("orientation", newOrientation).apply();

String orientation = mySPR.getInt("orientation", 0) == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ? "landscape" : "portrait";
Toasty.info(Objects.requireNonNull(getContext()), "Orientation changed to " + orientation, Toasty.LENGTH_SHORT).show();
Toasty.info(Objects.requireNonNull(getContext()), "Orientation changed to " + newOrientationName, Toasty.LENGTH_SHORT).show();
}
});

Expand Down Expand Up @@ -175,7 +195,7 @@ public void onClick(View view) {
credits_text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent termsOfUseIntent = new Intent(getContext(), Credits.class);
Intent termsOfUseIntent = new Intent(getContext(), About.class);
view.getContext().startActivity(termsOfUseIntent);
}
});
Expand All @@ -192,20 +212,39 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
}

private void statusWiederherstellung() {
MainActivity.changeOrientation(Objects.requireNonNull(getActivity()), mySPR.getInt("orientation", 0));

connectCheck.setChecked(mySPR.getBoolean("connectCheck", false));

if (mySPR.getBoolean("autoStart", false) && connectCheck.isChecked()) {
assert getFragmentManager() != null;
getFragmentManager().beginTransaction()
.replace(R.id.start, new WebViewFragment())
.addToBackStack(null)
.commit();
if (!mySPR.getBoolean("tempDisableStart", false)) {
if (mySPR.getBoolean("autoStart", false) && connectCheck.isChecked()) {
assert getFragmentManager() != null;
getFragmentManager().beginTransaction()
.replace(R.id.start, new WebViewFragment())
.addToBackStack(null)
.commit();

Toasty.info(Objects.requireNonNull(getContext()), getString(R.string.connecting), Toasty.LENGTH_SHORT).show();
}
} else {
Runnable runnable = new Runnable() {
@Override
public void run() {
editor.putBoolean("tempDisableStart", false).apply();
}
};

Toasty.info(getActivity().getApplicationContext(), getString(R.string.connecting), Toasty.LENGTH_SHORT).show();
new Handler().postDelayed(runnable, 10);
}

return;
switch (mySPR.getInt("orientation", 0)) {
case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
settings.setImageResource(R.drawable.icon_landscape_orientation);
break;
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
settings.setImageResource(R.drawable.icon_portrait_orientation);
break;
case ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED:
settings.setImageResource(R.drawable.icon_auto_orientation);
break;
}

if (mySPR.getString("hostnameIPAddressString", "").equals("") || mySPR.getString("hostnameIPAddressString", "").equals("0")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.thegreek.niko.logviewer_for_openHAB;

import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
Expand All @@ -10,11 +11,15 @@

import com.google.android.material.floatingactionbutton.FloatingActionButton;

import java.util.Objects;

public class PrivacyPolicy extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences mySPR = this.getSharedPreferences("Safe", 0);
MainActivity.changeOrientation(Objects.requireNonNull(this), mySPR.getInt("orientation", 0));
setContentView(R.layout.activity_privacy_policy);

TextView[] textViews = new TextView[21];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.thegreek.niko.logviewer_for_openHAB;

import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
Expand All @@ -10,11 +11,15 @@

import com.google.android.material.floatingactionbutton.FloatingActionButton;

import java.util.Objects;

public class TermsOfUse extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences mySPR = this.getSharedPreferences("Safe", 0);
MainActivity.changeOrientation(Objects.requireNonNull(this), mySPR.getInt("orientation", 0));
setContentView(R.layout.activity_terms_of_use);

TextView[] textViews = new TextView[7];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public void run() {
new TapTargetSequence(getActivity())
.targets(
TapTarget.forView(v.findViewById(R.id.view_button), getString(R.string.tap_target_title_1), getString(R.string.tap_target_message_1))
.transparentTarget(true)
.tintTarget(false)
.outerCircleColor(R.color.colorAccent)
.tintTarget(false)
Expand All @@ -160,6 +161,7 @@ public void run() {
.drawShadow(true)
.cancelable(false),
TapTarget.forView(v.findViewById(R.id.text_button), getString(R.string.tap_target_title_2), getString(R.string.tap_target_message_2))
.transparentTarget(true)
.tintTarget(false)
.outerCircleColor(R.color.colorAccent)
.tintTarget(false)
Expand All @@ -168,6 +170,7 @@ public void run() {
.drawShadow(true)
.cancelable(false),
TapTarget.forView(v.findViewById(R.id.back_utton), getString(R.string.tap_target_title_3), getString(R.string.tap_target_message_3))
.transparentTarget(true)
.tintTarget(false)
.outerCircleColor(R.color.colorAccent)
.tintTarget(false)
Expand Down
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 33e65f6

Please sign in to comment.