Merge lp:~openerp-dev/openerp-mobile/trunk-tablet-landscape-support-dpr into lp:openerp-mobile

Proposed by Dharmang Soni (OpenERP)
Status: Merged
Merged at revision: 157
Proposed branch: lp:~openerp-dev/openerp-mobile/trunk-tablet-landscape-support-dpr
Merge into: lp:openerp-mobile
Diff against target: 452 lines (+217/-41)
13 files modified
res/drawable-land/listitem_pressed.xml (+14/-0)
res/drawable-land/oe_listview_background_selector.xml (+8/-0)
res/drawable/two_pane_shadow.xml (+15/-0)
res/layout-land/activity_main.xml (+42/-0)
res/layout/fragment_idea.xml (+4/-8)
res/layout/fragment_idea_list_item.xml (+16/-0)
src/com/openerp/MainActivity.java (+49/-10)
src/com/openerp/addons/idea/Idea.java (+56/-22)
src/com/openerp/addons/idea/IdeaDetail.java (+5/-0)
src/com/openerp/config/ModulesConfig.java (+4/-1)
src/com/openerp/support/fragment/FragmentListener.java (+2/-0)
src/com/openerp/util/OEDate.java (+1/-0)
src/com/openerp/util/PreferenceManager.java (+1/-0)
To merge this branch: bzr merge lp:~openerp-dev/openerp-mobile/trunk-tablet-landscape-support-dpr
Reviewer Review Type Date Requested Status
OpenERP R&D Team Pending
Review via email: mp+218367@code.launchpad.net

Description of the change

Hello,

Landscape support added for tablet devices.

Thanks,
Dharmang Soni

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'res/drawable-hdpi/caret_grey.9.png'
2Binary files res/drawable-hdpi/caret_grey.9.png 1970-01-01 00:00:00 +0000 and res/drawable-hdpi/caret_grey.9.png 2014-05-06 09:00:02 +0000 differ
3=== added directory 'res/drawable-land'
4=== added file 'res/drawable-land/listitem_pressed.xml'
5--- res/drawable-land/listitem_pressed.xml 1970-01-01 00:00:00 +0000
6+++ res/drawable-land/listitem_pressed.xml 2014-05-06 09:00:02 +0000
7@@ -0,0 +1,14 @@
8+<?xml version="1.0" encoding="utf-8"?>
9+<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
10+
11+ <item>
12+ <shape>
13+ <gradient
14+ android:angle="270"
15+ android:endColor="#8bd7f0"
16+ android:startColor="#8bd7f0" />
17+ </shape>
18+ </item>
19+ <item android:drawable="@drawable/caret_grey"/>
20+
21+</layer-list>
22\ No newline at end of file
23
24=== added file 'res/drawable-land/oe_listview_background_selector.xml'
25--- res/drawable-land/oe_listview_background_selector.xml 1970-01-01 00:00:00 +0000
26+++ res/drawable-land/oe_listview_background_selector.xml 2014-05-06 09:00:02 +0000
27@@ -0,0 +1,8 @@
28+<?xml version="1.0" encoding="utf-8"?>
29+<selector xmlns:android="http://schemas.android.com/apk/res/android">
30+
31+ <item android:drawable="@drawable/listitem_pressed" android:state_activated="false" android:state_pressed="true"/>
32+ <item android:drawable="@drawable/listitem_focused" android:state_activated="true"/>
33+ <item android:drawable="@drawable/listitem_pressed" android:state_selected="true"/>
34+
35+</selector>
36\ No newline at end of file
37
38=== added file 'res/drawable-mdpi/caret_grey.9.png'
39Binary files res/drawable-mdpi/caret_grey.9.png 1970-01-01 00:00:00 +0000 and res/drawable-mdpi/caret_grey.9.png 2014-05-06 09:00:02 +0000 differ
40=== added file 'res/drawable-xhdpi/caret_grey.9.png'
41Binary files res/drawable-xhdpi/caret_grey.9.png 1970-01-01 00:00:00 +0000 and res/drawable-xhdpi/caret_grey.9.png 2014-05-06 09:00:02 +0000 differ
42=== added file 'res/drawable-xxhdpi/caret_grey.9.png'
43Binary files res/drawable-xxhdpi/caret_grey.9.png 1970-01-01 00:00:00 +0000 and res/drawable-xxhdpi/caret_grey.9.png 2014-05-06 09:00:02 +0000 differ
44=== added file 'res/drawable/two_pane_shadow.xml'
45--- res/drawable/two_pane_shadow.xml 1970-01-01 00:00:00 +0000
46+++ res/drawable/two_pane_shadow.xml 2014-05-06 09:00:02 +0000
47@@ -0,0 +1,15 @@
48+<?xml version="1.0" encoding="utf-8"?>
49+<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
50+
51+ <item>
52+ <shape android:shape="rectangle" >
53+ <solid android:color="#d1d1d1" />
54+ </shape>
55+ </item>
56+ <item android:left="1dp">
57+ <shape android:shape="rectangle" >
58+ <solid android:color="#ffffff" />
59+ </shape>
60+ </item>
61+
62+</layer-list>
63\ No newline at end of file
64
65=== added directory 'res/layout-land'
66=== added file 'res/layout-land/activity_main.xml'
67--- res/layout-land/activity_main.xml 1970-01-01 00:00:00 +0000
68+++ res/layout-land/activity_main.xml 2014-05-06 09:00:02 +0000
69@@ -0,0 +1,42 @@
70+<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
71+ android:id="@+id/drawer_layout"
72+ android:layout_width="match_parent"
73+ android:layout_height="match_parent"
74+ android:background="#ffffff" >
75+
76+ <LinearLayout
77+ android:layout_width="match_parent"
78+ android:layout_height="match_parent"
79+ android:baselineAligned="false"
80+ android:divider="?android:attr/dividerHorizontal"
81+ android:orientation="horizontal"
82+ android:showDividers="middle" >
83+
84+ <FrameLayout
85+ android:id="@+id/fragment_container"
86+ android:layout_width="0dp"
87+ android:layout_height="match_parent"
88+ android:layout_weight="0.8"
89+ android:background="#ffffff" />
90+
91+ <FrameLayout
92+ android:id="@+id/fragment_detail_container"
93+ android:layout_width="0dp"
94+ android:layout_height="match_parent"
95+ android:layout_weight="1.2"
96+ android:background="#ffffff" />
97+ </LinearLayout>
98+
99+ <ListView
100+ android:id="@+id/left_drawer"
101+ android:layout_width="280dp"
102+ android:layout_height="match_parent"
103+ android:layout_gravity="start|bottom"
104+ android:layout_marginTop="?android:attr/actionBarSize"
105+ android:background="#ffffff"
106+ android:choiceMode="singleChoice"
107+ android:divider="#E3E9E3"
108+ android:dividerHeight="1dp"
109+ android:smoothScrollbar="true" />
110+
111+</android.support.v4.widget.DrawerLayout>
112\ No newline at end of file
113
114=== modified file 'res/layout/fragment_idea.xml'
115--- res/layout/fragment_idea.xml 2014-04-23 05:20:53 +0000
116+++ res/layout/fragment_idea.xml 2014-05-06 09:00:02 +0000
117@@ -5,14 +5,10 @@
118 android:orientation="vertical"
119 android:paddingTop="?android:attr/actionBarSize" >
120
121- <TextView
122- android:id="@+id/txvIdeaFragment"
123+ <ListView
124+ android:id="@+id/listview"
125 android:layout_width="match_parent"
126- android:layout_height="match_parent"
127- android:fontFamily="sans-sarif-light"
128- android:gravity="center"
129- android:text="Idea Fragment"
130- android:textAppearance="?android:attr/textAppearanceLarge"
131- android:textStyle="bold" />
132+ android:layout_height="match_parent" >
133+ </ListView>
134
135 </LinearLayout>
136\ No newline at end of file
137
138=== added file 'res/layout/fragment_idea_list_item.xml'
139--- res/layout/fragment_idea_list_item.xml 1970-01-01 00:00:00 +0000
140+++ res/layout/fragment_idea_list_item.xml 2014-05-06 09:00:02 +0000
141@@ -0,0 +1,16 @@
142+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
143+ android:layout_width="match_parent"
144+ android:layout_height="match_parent"
145+ android:background="@drawable/oe_listview_background_selector"
146+ android:padding="15dp" >
147+
148+ <TextView
149+ android:id="@+id/txvIdeaName"
150+ android:layout_width="match_parent"
151+ android:layout_height="match_parent"
152+ android:fontFamily="sans-sarif-light"
153+ android:text="Idea Fragment"
154+ android:textAppearance="?android:attr/textAppearanceLarge"
155+ android:textStyle="bold" />
156+
157+</LinearLayout>
158\ No newline at end of file
159
160=== modified file 'src/com/openerp/MainActivity.java'
161--- src/com/openerp/MainActivity.java 2014-04-22 13:11:23 +0000
162+++ src/com/openerp/MainActivity.java 2014-05-06 09:00:02 +0000
163@@ -89,6 +89,7 @@
164 String mDrawerSubtitle = "";
165 int mDrawerItemSelectedPosition = -1;
166 ListView mDrawerListView = null;
167+ boolean mNewFragment = false;
168
169 FragmentManager mFragment = null;
170
171@@ -99,7 +100,7 @@
172 private CharSequence mTitle;
173 private OETouchListener mTouchAttacher;
174 private OnBackButtonPressedListener backPressed = null;
175- private boolean mLandscape = false;
176+ private boolean mTwoPane;
177
178 @Override
179 protected void onCreate(Bundle savedInstanceState) {
180@@ -112,10 +113,11 @@
181 }
182 mContext = this;
183 mFragment = getSupportFragmentManager();
184- if (findViewById(R.id.fragment_container) != null) {
185- mLandscape = false;
186- } else {
187- mLandscape = true;
188+ if (findViewById(R.id.fragment_detail_container) != null) {
189+ findViewById(R.id.fragment_detail_container).setVisibility(
190+ View.GONE);
191+
192+ mTwoPane = true;
193 }
194 init();
195 }
196@@ -696,8 +698,19 @@
197 @Override
198 public void startMainFragment(Fragment fragment, boolean addToBackState) {
199 Log.d(TAG, "MainActivity->FragmentListener->startMainFragment()");
200+ int container_id = R.id.fragment_container;
201+
202+ if (isTwoPane()) {
203+ findViewById(R.id.fragment_detail_container).setVisibility(
204+ View.GONE);
205+ Fragment detail = mFragment.findFragmentByTag("detail_fragment");
206+ if (detail != null && !mNewFragment && !detail.isInLayout()) {
207+ startDetailFragment(recreateFragment(detail));
208+ }
209+
210+ }
211 FragmentTransaction tran = mFragment.beginTransaction().replace(
212- R.id.fragment_container, fragment);
213+ container_id, fragment, "main_fragment");
214 if (addToBackState) {
215 tran.addToBackStack(null);
216 }
217@@ -707,12 +720,33 @@
218 @Override
219 public void startDetailFragment(Fragment fragment) {
220 Log.d(TAG, "MainActivity->FragmentListener->startDetailFragment()");
221+ int container_id = (isTwoPane()) ? R.id.fragment_detail_container
222+ : R.id.fragment_container;
223 FragmentTransaction tran = mFragment.beginTransaction().replace(
224- R.id.fragment_container, fragment);
225- if (!mLandscape) {
226+ container_id, fragment, "detail_fragment");
227+ if (!isTwoPane()) {
228 tran.addToBackStack(null);
229- }
230- tran.commit();
231+ tran.commit();
232+ } else {
233+ findViewById(R.id.fragment_detail_container).setVisibility(
234+ View.VISIBLE);
235+ tran.commitAllowingStateLoss();
236+ }
237+ }
238+
239+ private Fragment recreateFragment(Fragment fragment) {
240+ Log.d(TAG, "recreateFragment()");
241+ Fragment newInstance = null;
242+ try {
243+ Fragment.SavedState savedState = mFragment
244+ .saveFragmentInstanceState(fragment);
245+
246+ newInstance = fragment.getClass().newInstance();
247+ newInstance.setInitialSavedState(savedState);
248+ } catch (Exception e) {
249+ e.printStackTrace();
250+ }
251+ return newInstance;
252 }
253
254 @Override
255@@ -721,4 +755,9 @@
256 getIntent().putExtra("create_new_account", false);
257 init();
258 }
259+
260+ @Override
261+ public boolean isTwoPane() {
262+ return mTwoPane;
263+ }
264 }
265
266=== modified file 'src/com/openerp/addons/idea/Idea.java'
267--- src/com/openerp/addons/idea/Idea.java 2014-04-23 07:29:00 +0000
268+++ src/com/openerp/addons/idea/Idea.java 2014-05-06 09:00:02 +0000
269@@ -25,11 +25,18 @@
270 import android.content.Context;
271 import android.os.Bundle;
272 import android.view.LayoutInflater;
273+import android.view.Menu;
274+import android.view.MenuInflater;
275 import android.view.View;
276-import android.view.View.OnClickListener;
277 import android.view.ViewGroup;
278+import android.widget.AdapterView;
279+import android.widget.AdapterView.OnItemClickListener;
280+import android.widget.ArrayAdapter;
281+import android.widget.ListView;
282+import android.widget.TextView;
283
284 import com.openerp.R;
285+import com.openerp.orm.OEDataRow;
286 import com.openerp.support.BaseFragment;
287 import com.openerp.support.fragment.FragmentListener;
288 import com.openerp.util.drawer.DrawerItem;
289@@ -37,32 +44,43 @@
290 /**
291 * The Class Idea.
292 */
293-public class Idea extends BaseFragment {
294+public class Idea extends BaseFragment implements OnItemClickListener {
295+
296+ List<String> mItems = new ArrayList<String>();
297+ ListView mListView = null;
298
299 public View onCreateView(LayoutInflater inflater, ViewGroup container,
300 Bundle savedInstanceState) {
301+ setHasOptionsMenu(true);
302 View rootView = inflater.inflate(R.layout.fragment_idea, container,
303 false);
304- // Res_PartnerDBHelper partner = new Res_PartnerDBHelper(getActivity());
305- // boolean flag = partner.getOEInstance().syncWithServer();
306- // OELog.log("Synced: " + flag);
307-
308- // DrawerListener drawer = (DrawerListener) getActivity();
309- // drawer.refreshDrawer("idea");
310- IdeaDemoRecords rec = new IdeaDemoRecords(getActivity());
311- rec.createDemoRecords();
312- rec.selectAll();
313- rootView.findViewById(R.id.txvIdeaFragment).setOnClickListener(
314- new OnClickListener() {
315-
316- @Override
317- public void onClick(View v) {
318-
319- FragmentListener frag = (FragmentListener) getActivity();
320- frag.startDetailFragment(new IdeaDetail());
321-
322- }
323- });
324+
325+ if (db().isEmptyTable()) {
326+ IdeaDemoRecords rec = new IdeaDemoRecords(getActivity());
327+ rec.createDemoRecords();
328+ }
329+
330+ mItems.clear();
331+ for (OEDataRow row : db().select()) {
332+ mItems.add(row.getString("name"));
333+ }
334+
335+ mListView = (ListView) rootView.findViewById(R.id.listview);
336+ mListView.setAdapter(new ArrayAdapter<String>(getActivity(),
337+ R.layout.fragment_idea_list_item, mItems) {
338+ @Override
339+ public View getView(int position, View convertView, ViewGroup parent) {
340+ View mView = convertView;
341+ if (mView == null)
342+ mView = getActivity().getLayoutInflater().inflate(
343+ R.layout.fragment_idea_list_item, parent, false);
344+ TextView txv = (TextView) mView.findViewById(R.id.txvIdeaName);
345+ txv.setText(mItems.get(position));
346+ return mView;
347+ }
348+
349+ });
350+ mListView.setOnItemClickListener(this);
351 return rootView;
352 }
353
354@@ -83,4 +101,20 @@
355 return menu;
356 }
357
358+ @Override
359+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
360+ inflater.inflate(R.menu.menu_fragment_account, menu);
361+ }
362+
363+ @Override
364+ public void onItemClick(AdapterView<?> parent, View view, int position,
365+ long id) {
366+ view.setSelected(true);
367+ IdeaDetail detail = new IdeaDetail();
368+ Bundle args = new Bundle();
369+ args.putString("name", mItems.get(position));
370+ detail.setArguments(args);
371+ FragmentListener frag = (FragmentListener) getActivity();
372+ frag.startDetailFragment(detail);
373+ }
374 }
375
376=== modified file 'src/com/openerp/addons/idea/IdeaDetail.java'
377--- src/com/openerp/addons/idea/IdeaDetail.java 2014-05-01 05:47:22 +0000
378+++ src/com/openerp/addons/idea/IdeaDetail.java 2014-05-06 09:00:02 +0000
379@@ -25,6 +25,7 @@
380 import android.view.LayoutInflater;
381 import android.view.View;
382 import android.view.ViewGroup;
383+import android.widget.TextView;
384
385 import com.openerp.R;
386 import com.openerp.support.BaseFragment;
387@@ -37,6 +38,10 @@
388 Bundle savedInstanceState) {
389 View mView = inflater.inflate(R.layout.fragment_idea_detail, container,
390 false);
391+ Bundle args = getArguments();
392+ TextView txv = (TextView) mView.findViewById(R.id.textView1);
393+ if (args != null && args.containsKey("name"))
394+ txv.setText(args.getString("name"));
395 return mView;
396 }
397
398
399=== modified file 'src/com/openerp/config/ModulesConfig.java'
400--- src/com/openerp/config/ModulesConfig.java 2014-04-23 05:20:53 +0000
401+++ src/com/openerp/config/ModulesConfig.java 2014-05-06 09:00:02 +0000
402@@ -18,6 +18,8 @@
403 */
404 package com.openerp.config;
405
406+import com.openerp.addons.idea.Idea;
407+import com.openerp.support.Module;
408 import com.openerp.support.ModulesConfigHelper;
409
410 /**
411@@ -30,6 +32,7 @@
412 */
413 public ModulesConfig() {
414 /* application modules */
415- //add(new Module("module_idea", "Idea", new Idea(), 0), true);
416+
417+ add(new Module("module_idea", "Idea", new Idea(), 0), true);
418 }
419 }
420
421=== modified file 'src/com/openerp/support/fragment/FragmentListener.java'
422--- src/com/openerp/support/fragment/FragmentListener.java 2014-03-20 11:27:48 +0000
423+++ src/com/openerp/support/fragment/FragmentListener.java 2014-05-06 09:00:02 +0000
424@@ -26,4 +26,6 @@
425 public void startDetailFragment(Fragment fragment);
426
427 public void restart();
428+
429+ public boolean isTwoPane();
430 }
431
432=== modified file 'src/com/openerp/util/OEDate.java'
433--- src/com/openerp/util/OEDate.java 2014-04-23 09:28:32 +0000
434+++ src/com/openerp/util/OEDate.java 2014-05-06 09:00:02 +0000
435@@ -50,6 +50,7 @@
436 if (date.equals("false")) {
437 return date;
438 }
439+
440 Calendar cal = Calendar.getInstance();
441 Date originalDate = convertToDate(date);
442 cal.setTime(originalDate);
443
444=== modified file 'src/com/openerp/util/PreferenceManager.java'
445--- src/com/openerp/util/PreferenceManager.java 2014-03-20 11:27:48 +0000
446+++ src/com/openerp/util/PreferenceManager.java 2014-05-06 09:00:02 +0000
447@@ -32,4 +32,5 @@
448 public int getInt(String key, int default_value) {
449 return Integer.parseInt(mPref.getString(key, default_value + ""));
450 }
451+
452 }