Permalink
Browse files

[+] Adding a phone interface

  • Loading branch information...
1 parent 0c987e2 commit 4e049a341aad78ce46f78671fa7c74ab0e1aeed9 @artiomchi committed Apr 1, 2012
View
5 AndroidManifest.xml
@@ -24,13 +24,14 @@
</receiver>
<!-- Widget widgetsettings activity -->
<activity android:name=".widgetsettings.WidgetActivity" android:excludeFromRecents="true"
- android:label="Widget Properties" android:theme="@style/Theme.Sherlock">
+ android:label="Widget Properties" android:theme="@style/Theme.FlexLabs">
<intent-filter><action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" /></intent-filter>
</activity>
<activity android:name=".widgetsettings.WidgetSettingsActivity" android:excludeFromRecents="true"
- android:label="Widget Properties" android:theme="@style/Theme.Sherlock"/>
+ android:label="Widget Properties" android:theme="@style/Theme.FlexLabs"/>
<activity android:name=".widgetsettings.WidgetTabbedActivity" android:excludeFromRecents="true"
android:label="Widget Properties"/>
+ <!-- Welcome Activity -->
<activity android:name=".WelcomeActivity" android:theme="@android:style/Theme.Holo.Light.Dialog">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
View
17 res/layout/about.xml
@@ -1,4 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ ~ Copyright 2012 Artiom Chilaru (http://flexlabs.org)
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"
View
17 res/layout/battery_info_table.xml
@@ -1,4 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ ~ Copyright 2012 Artiom Chilaru (http://flexlabs.org)
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:id="@+id/body">
View
17 res/layout/donate_summary.xml
@@ -1,4 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ ~ Copyright 2012 Artiom Chilaru (http://flexlabs.org)
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:padding="5dp">
View
17 res/layout/feedback_form.xml
@@ -1,4 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ ~ Copyright 2012 Artiom Chilaru (http://flexlabs.org)
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
View
17 res/layout/seekbar_dialog.xml
@@ -1,4 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ ~ Copyright 2012 Artiom Chilaru (http://flexlabs.org)
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
View
17 res/layout/welcome.xml
@@ -1,4 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ ~ Copyright 2012 Artiom Chilaru (http://flexlabs.org)
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="15dp" android:paddingBottom="25dp">
View
17 res/layout/widget.xml
@@ -1,4 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ ~ Copyright 2012 Artiom Chilaru (http://flexlabs.org)
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/widget">
View
26 res/layout/widgetsettings.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ ~ Copyright 2012 Artiom Chilaru (http://flexlabs.org)
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent" android:layout_height="fill_parent"
+ android:orientation="vertical">
+ <com.viewpagerindicator.TabPageIndicator android:id="@+id/indicator"
+ android:layout_width="fill_parent" android:layout_height="wrap_content" />
+ <android.support.v4.view.ViewPager android:id="@+id/pager"
+ android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" />
+</LinearLayout>
View
4 res/values/styles.xml
@@ -32,4 +32,8 @@
<item name="android:textSize">16sp</item>
<item name="android:textStyle">normal</item>
</style>
+ <style name="Theme.FlexLabs" parent="@style/Theme.Sherlock">
+ <item name="vpiTabPageIndicatorStyle">@style/Widget.TabPageIndicator</item>
+ <item name="vpiTabTextStyle">@style/Widget.TabPageIndicator.Text</item>
+ </style>
</resources>
View
4 src/org/flexlabs/widgets/dualbattery/widgetsettings/DonateFragment.java
@@ -78,8 +78,8 @@ public void onClick(View view) {
private final View.OnClickListener payPalDonateListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
- mMixPanel.track(MixPanelComponent.DONATE_PAYPAL, null);
- getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.URI_PAYPAL)));
+ mMixPanel.track(MixPanelComponent.DONATE_PAYPAL, null);
+ getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.URI_PAYPAL)));
}
};
}
View
42 src/org/flexlabs/widgets/dualbattery/widgetsettings/FeedbackFragment.java
@@ -17,6 +17,7 @@
package org.flexlabs.widgets.dualbattery.widgetsettings;
import android.app.Fragment;
+import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
@@ -54,25 +55,30 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
feedbackEditor = (EditText)view.findViewById(R.id.feedbackEditor);
feedbackEditor.requestFocus();
- view.findViewById(R.id.sendFeedback).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- mMixPanel.track(MixPanelComponent.BATTERY_INFO_FEEDBACK, null);
- Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
- intent.putExtra(Intent.EXTRA_EMAIL, new String[] { Constants.FeedbackDestination });
- intent.putExtra(Intent.EXTRA_SUBJECT, "Dual Battery Widget Feedback");
- intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(getDeviceDetails()));
- intent.setType("message/rfc822");
- getActivity().startActivity(Intent.createChooser(intent, "Email"));
-
- feedbackEditor.setText(null);
- }
- });
+ view.findViewById(R.id.sendFeedback).setOnClickListener(feedbackListener);
return view;
}
- private String getDeviceDetails() {
- StringBuilder sb = new StringBuilder(feedbackEditor.getText());
+ private final View.OnClickListener feedbackListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ sendFeedback(mMixPanel, getActivity(), feedbackEditor.getText());
+ feedbackEditor.setText(null);
+ }
+ };
+
+ public static void sendFeedback(MixPanelComponent mMixPanel, Context context, CharSequence feedback) {
+ mMixPanel.track(MixPanelComponent.BATTERY_INFO_FEEDBACK, null);
+ Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
+ intent.putExtra(Intent.EXTRA_EMAIL, new String[] { Constants.FeedbackDestination });
+ intent.putExtra(Intent.EXTRA_SUBJECT, "Dual Battery Widget Feedback");
+ intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(getDeviceDetails(context, feedback)));
+ intent.setType("message/rfc822");
+ context.startActivity(Intent.createChooser(intent, "Email"));
+ }
+
+ private static String getDeviceDetails(Context context, CharSequence feedback) {
+ StringBuilder sb = new StringBuilder(feedback);
sb.append("<br />\n<h4>Device details:</h4>");
sb.append("<br />\n<b>App version:</b> ").append(Constants.VERSION);
sb.append("<br />\n<b>Brand:</b> ").append(Build.MANUFACTURER);
@@ -81,7 +87,7 @@ private String getDeviceDetails() {
sb.append("<br />\n<b>Android version:</b> ").append(Build.VERSION.RELEASE);
sb.append("<br />\n<b>Version details:</b> ").append(Build.VERSION.INCREMENTAL);
- Intent intent = getActivity().registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
+ Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Bundle extras = intent.getExtras();
String allKeys = TextUtils.join(", ", extras.keySet());
sb.append("<br />\n<b>Battery intent keys:</b> ").append(allKeys);
@@ -103,7 +109,7 @@ private String getDeviceDetails() {
return sb.toString();
}
- private String getFormattedKernelVersion() {
+ private static String getFormattedKernelVersion() {
String procVersionStr;
try {
View
47 src/org/flexlabs/widgets/dualbattery/widgetsettings/SherlockAboutFragment.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2012 Artiom Chilaru (http://flexlabs.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.flexlabs.widgets.dualbattery.widgetsettings;
+
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.text.util.Linkify;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+import com.actionbarsherlock.app.SherlockFragment;
+import org.flexlabs.widgets.dualbattery.Constants;
+import org.flexlabs.widgets.dualbattery.R;
+
+public class SherlockAboutFragment extends SherlockFragment {
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.about, null);
+ TextView aboutText = (TextView)view.findViewById(R.id.about_text);
+ Linkify.addLinks(aboutText, Linkify.ALL);
+ view.findViewById(R.id.play_logo).setOnClickListener(playLogoListener);
+ return view;
+ }
+
+ private final View.OnClickListener playLogoListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.URI_GOOGLE_PLAY)));
+ }
+ };
+}
View
81 src/org/flexlabs/widgets/dualbattery/widgetsettings/SherlockBatteryInfoFragment.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2012 Artiom Chilaru (http://flexlabs.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.flexlabs.widgets.dualbattery.widgetsettings;
+
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import com.actionbarsherlock.app.SherlockFragment;
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuInflater;
+import org.flexlabs.widgets.dualbattery.R;
+
+public class SherlockBatteryInfoFragment extends SherlockFragment {
+ private IntentFilter mIntentFilter;
+ private BatteryInfoViewManager _batteryInfoViewManager;
+ private BatteryInfoViewManager batteryInfoViewManager() {
+ if (_batteryInfoViewManager == null)
+ _batteryInfoViewManager = ((WidgetActivity)getSherlockActivity()).batteryInfoViewManager;
+ return _batteryInfoViewManager;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setHasOptionsMenu(true);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.battery_info_table, null);
+ WidgetActivity activity = (WidgetActivity)getActivity();
+ int appWidgetId = activity.appWidgetId;
+ view.findViewById(R.id.batterySummary).setOnClickListener(batteryInfoViewManager().batterySummaryListener);
+ batteryInfoViewManager().loadData(getActivity(), view, appWidgetId);
+ mIntentFilter = new IntentFilter();
+ mIntentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
+
+ return view;
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ getActivity().unregisterReceiver(batteryInfoViewManager());
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ getActivity().registerReceiver(batteryInfoViewManager(), mIntentFilter);
+ batteryInfoViewManager().buildChart();
+ }
+
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ inflater.inflate(R.menu.widget_batteryinfo, menu);
+ }
+
+ @Override
+ public void onPrepareOptionsMenu(Menu menu) {
+ super.onPrepareOptionsMenu(menu);
+ menu.findItem(R.id.temperature).setTitle(batteryInfoViewManager().getMenuTitle());
+ }
+}
View
85 src/org/flexlabs/widgets/dualbattery/widgetsettings/SherlockDonateFragment.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2012 Artiom Chilaru (http://flexlabs.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.flexlabs.widgets.dualbattery.widgetsettings;
+
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import com.actionbarsherlock.app.SherlockFragment;
+import net.robotmedia.billing.BillingController;
+import org.flexlabs.widgets.dualbattery.Constants;
+import org.flexlabs.widgets.dualbattery.MixPanelComponent;
+import org.flexlabs.widgets.dualbattery.R;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+public class SherlockDonateFragment extends SherlockFragment {
+ private MixPanelComponent mMixPanel;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.donate_summary, null);
+ if (mMixPanel == null) {
+ mMixPanel = new MixPanelComponent(getActivity());
+ mMixPanel.track(MixPanelComponent.BATTERY_INFO, null);
+ }
+ if (!Constants.HAS_GPLAY_BILLING) {
+ view.findViewById(R.id.donate_play).setVisibility(View.GONE);
+ view.findViewById(R.id.donate_play_options).setVisibility(View.GONE);
+ }
+
+ view.findViewById(R.id.donate_play_1).setOnClickListener(playDonateListener);
+ view.findViewById(R.id.donate_play_3).setOnClickListener(playDonateListener);
+ view.findViewById(R.id.donate_play_7).setOnClickListener(playDonateListener);
+ view.findViewById(R.id.donate_paypal).setOnClickListener(payPalDonateListener);
+ return view;
+ }
+
+ private final View.OnClickListener playDonateListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ String playItem = "donation.amount.0.99";
+ switch (view.getId()) {
+ case R.id.donate_play_3:
+ playItem = "donation.amount.3.00";
+ break;
+ case R.id.donate_play_7 :
+ playItem = "donation.amount.7.77";
+ break;
+ }
+ JSONObject properties = new JSONObject();
+ try {
+ properties.put("item", playItem);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ mMixPanel.track(MixPanelComponent.DONATE_GPLAY_PACKAGE, properties);
+ BillingController.requestPurchase(getActivity(), playItem, true);
+ }
+ };
+
+ private final View.OnClickListener payPalDonateListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ mMixPanel.track(MixPanelComponent.DONATE_PAYPAL, null);
+ getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.URI_PAYPAL)));
+ }
+ };
+}
View
53 src/org/flexlabs/widgets/dualbattery/widgetsettings/SherlockFeedbackFragment.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2012 Artiom Chilaru (http://flexlabs.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.flexlabs.widgets.dualbattery.widgetsettings;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.EditText;
+import com.actionbarsherlock.app.SherlockFragment;
+import org.flexlabs.widgets.dualbattery.MixPanelComponent;
+import org.flexlabs.widgets.dualbattery.R;
+
+public class SherlockFeedbackFragment extends SherlockFragment {
+ private EditText feedbackEditor;
+ private MixPanelComponent mMixPanel;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.feedback_form, null);
+ if (mMixPanel == null) {
+ mMixPanel = new MixPanelComponent(getActivity());
+ mMixPanel.track(MixPanelComponent.BATTERY_INFO, null);
+ }
+ feedbackEditor = (EditText)view.findViewById(R.id.feedbackEditor);
+ feedbackEditor.requestFocus();
+
+ view.findViewById(R.id.sendFeedback).setOnClickListener(feedbackListener);
+ return view;
+ }
+
+ private final View.OnClickListener feedbackListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ FeedbackFragment.sendFeedback(mMixPanel, getActivity(), feedbackEditor.getText());
+ feedbackEditor.setText(null);
+ }
+ };
+}
View
104 src/org/flexlabs/widgets/dualbattery/widgetsettings/WidgetActivity.java
@@ -18,22 +18,29 @@
import android.appwidget.AppWidgetManager;
import android.content.Intent;
-import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
-import android.view.View;
-import android.widget.Button;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentPagerAdapter;
+import android.support.v4.view.ViewPager;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
+import com.viewpagerindicator.PageIndicator;
+import com.viewpagerindicator.TabPageIndicator;
+import com.viewpagerindicator.TitleProvider;
import org.flexlabs.widgets.dualbattery.R;
public class WidgetActivity extends SherlockFragmentActivity {
- private int appWidgetId;
- private IntentFilter intentFilter;
- private BatteryInfoViewManager batteryInfoViewManager = new BatteryInfoViewManager();
+ public int appWidgetId;
+ public BatteryInfoViewManager batteryInfoViewManager = new BatteryInfoViewManager();
+
+ TabAdapter mAdapter;
+ ViewPager mPager;
+ PageIndicator mIndicator;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -52,22 +59,56 @@ public void onCreate(Bundle savedInstanceState) {
return;
}
- setContentView(R.layout.battery_info_table);
- intentFilter = new IntentFilter();
- intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
- batteryInfoViewManager.loadData(this, findViewById(R.id.body), appWidgetId);
- findViewById(R.id.batterySummary).setOnClickListener(batteryInfoViewManager.batterySummaryListener);
- Button widgetSettings = (Button)findViewById(R.id.widgetSettings);
- widgetSettings.setVisibility(View.VISIBLE);
- widgetSettings.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent newIntent = new Intent(WidgetActivity.this, WidgetSettingsActivity.class);
- newIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
- startActivity(newIntent);
- finish();
+ setContentView(R.layout.widgetsettings);
+ mAdapter = new TabAdapter(getSupportFragmentManager());
+ mPager = (ViewPager)findViewById(R.id.pager);
+ mPager.setAdapter(mAdapter);
+
+ mIndicator = (TabPageIndicator)findViewById(R.id.indicator);
+ mIndicator.setViewPager(mPager);
+ }
+
+ class TabAdapter extends FragmentPagerAdapter implements TitleProvider {
+ public TabAdapter(FragmentManager fm) {
+ super(fm);
+ }
+
+ @Override
+ public Fragment getItem(int i) {
+ switch (i) {
+ case 0:
+ return new SherlockBatteryInfoFragment();
+ case 1:
+ return new SherlockFeedbackFragment();
+ case 2:
+ return new SherlockDonateFragment();
+ case 3:
+ return new SherlockAboutFragment();
+ default:
+ return null;
+ }
+ }
+
+ @Override
+ public int getCount() {
+ return 4;
+ }
+
+ @Override
+ public String getTitle(int position) {
+ switch(position) {
+ case 0:
+ return getString(R.string.propTitle_General);
+ case 1:
+ return getString(R.string.propTitle_Feedback);
+ case 2:
+ return getString(R.string.propTitle_Donate);
+ case 3:
+ return getString(R.string.propTitle_About);
+ default:
+ return null;
}
- });
+ }
}
@Override
@@ -77,34 +118,13 @@ protected void onDestroy() {
}
@Override
- public void onPause() {
- super.onPause();
- unregisterReceiver(batteryInfoViewManager);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- registerReceiver(batteryInfoViewManager, intentFilter);
- batteryInfoViewManager.buildChart();
- }
-
- @Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
- inflater.inflate(R.menu.widget_batteryinfo, menu);
inflater.inflate(R.menu.widget, menu);
return true;
}
@Override
- public boolean onPrepareOptionsMenu(Menu menu) {
- super.onPrepareOptionsMenu(menu);
- menu.findItem(R.id.temperature).setTitle(batteryInfoViewManager.getMenuTitle());
- return true;
- }
-
- @Override
public boolean onOptionsItemSelected(MenuItem item) {
return batteryInfoViewManager.onMenuItemSelected(item) ||
super.onOptionsItemSelected(item);

0 comments on commit 4e049a3

Please sign in to comment.