Skip to content

Commit

Permalink
added fullscreen option
Browse files Browse the repository at this point in the history
  • Loading branch information
ns130291 committed Feb 12, 2018
1 parent 1ffd3f5 commit 10e99ee
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ android {
applicationId "de.nsvb.android.auto.widget"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "0.1.0"
versionCode 2
versionName "0.2.0"
}

ext{
ext {
APP_NAME = "@string/app_name"
}

Expand All @@ -32,6 +32,7 @@ android {
}

dependencies {
implementation 'com.android.support:support-v4:27.0.2'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support:cardview-v7:27.0.2'
Expand Down
16 changes: 12 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<service
android:name="de.nsvb.android.auto.widget.CarService"
android:name=".CarService"
android:label="@string/car_service_name"
tools:ignore="ExportedService">
<intent-filter>
Expand All @@ -23,7 +23,7 @@
</service>

<activity
android:name="de.nsvb.android.auto.widget.ConfigurationActivity"
android:name=".ConfigurationActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -37,14 +37,22 @@
android:resource="@xml/automotive_app_desc" />

<activity
android:name="de.nsvb.android.auto.widget.AboutActivity"
android:name=".AboutActivity"
android:label="@string/title_activity_about"
android:parentActivityName="de.nsvb.android.auto.widget.ConfigurationActivity"
android:parentActivityName=".ConfigurationActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="de.nsvb.android.auto.widget.ConfigurationActivity" />
</activity>
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName=".ConfigurationActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="de.nsvb.android.auto.widget.ConfigurationActivity" />
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
package de.nsvb.android.auto.widget;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.TextView;

import com.github.martoreto.aademo.BuildConfig;
import com.github.martoreto.aademo.R;

public class AboutActivity extends AppCompatActivity {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import android.widget.Toast;
import android.widget.Toolbar;

import com.github.martoreto.aademo.R;

/**
* Created by ns130291 on 27.01.2018.
*/
Expand Down Expand Up @@ -127,6 +125,9 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.settings:
startActivity(new Intent(this, SettingsActivity.class));
break;
case R.id.about:
startActivity(new Intent(this, AboutActivity.class));
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package de.nsvb.android.auto.widget;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.util.Log;

import com.github.martoreto.aademo.R;
import com.google.android.apps.auto.sdk.CarActivity;
import com.google.android.apps.auto.sdk.CarUiController;
import com.google.android.apps.auto.sdk.StatusBarController;
Expand Down Expand Up @@ -60,6 +61,13 @@ public void onCreate(Bundle bundle) {
//statusBarController.setAppBarAlpha(1f);
//statusBarController.setAppBarBackgroundColor(getResources().getColor(R.color.car_accent));
statusBarController.setTitle(getResources().getText(R.string.app_name));

boolean fullscreen = getSharedPreferences(ConfigurationActivity.PREFS_NAME, Context.MODE_PRIVATE)
.getBoolean(getString(R.string.key_fullscreen_switch), false);
Log.d(TAG, "fullscreen=" + fullscreen);
if(fullscreen) {
statusBarController.hideAppHeader();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.nsvb.android.auto.widget;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SettingsActivity extends AppCompatActivity {

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

// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.nsvb.android.auto.widget;

import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.support.annotation.Nullable;

/**
* Created by ns130291 on 12.02.2018.
*/

public class SettingsFragment extends PreferenceFragment {

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

getPreferenceManager().setSharedPreferencesName(ConfigurationActivity.PREFS_NAME);

addPreferencesFromResource(R.xml.pref_general);
}
}
14 changes: 12 additions & 2 deletions app/src/main/java/de/nsvb/android/auto/widget/WidgetFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.github.martoreto.aademo.R;

/**
* Created by ns130291 on 27.01.2018.
*/
Expand All @@ -31,6 +31,7 @@ public class WidgetFragment extends CarFragment {
private AppWidgetHostView mHostView;

private int widgetID = -1;
private boolean fullscreen = false;

public WidgetFragment(){
setTitle("WidgetViewer");
Expand All @@ -42,6 +43,9 @@ public void onAttach(Context context) {

Log.d(TAG, "onAttach");

fullscreen = context.getSharedPreferences(ConfigurationActivity.PREFS_NAME, Context.MODE_PRIVATE)
.getBoolean(getString(R.string.key_fullscreen_switch), false);

mAppWidgetManager = AppWidgetManager.getInstance(context);
mAppWidgetHost = new AppWidgetHost(context, 123456);

Expand All @@ -55,6 +59,12 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
View view = inflater.inflate(R.layout.fragment_widget, container, false);

mWidgetContainer = view.findViewById(R.id.widget_container);
if(fullscreen) {
ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) mWidgetContainer.getLayoutParams();
layoutParams.setMargins(0,
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16,
getResources().getDisplayMetrics()), 0, 0);
}

/*int widgetID = getActivity().getPreferences(Context.MODE_PRIVATE).getInt(ConfigurationActivity.WIDGET_ID, -1);
if(widgetID != -1) {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/menu/menu_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">


<item
android:id="@+id/settings"
android:title="@string/settings"
app:showAsAction="ifRoom" />
<item
android:id="@+id/about"
android:title="@string/about"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/settings_keys.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="key_fullscreen_switch">fullscreen_switch</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
<string name="car_service_name">Widgets</string>
<string name="title_activity_about">About</string>
<string name="about">About</string>
<string name="title_activity_settings">Settings</string>
<string name="pref_desc_fullscreen">Show widgets fullscreen</string>
<string name="pref_fullscreen">Fullscreen widgets</string>
<string name="settings">Settings</string>
</resources>
9 changes: 9 additions & 0 deletions app/src/main/res/xml/pref_general.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<SwitchPreference
android:defaultValue="false"
android:key="@string/key_fullscreen_switch"
android:summary="@string/pref_desc_fullscreen"
android:title="@string/pref_fullscreen" />

</PreferenceScreen>

0 comments on commit 10e99ee

Please sign in to comment.