Skip to content
This repository
Browse code

Adaptation for large-screen Android 3.0+ is done!

  • Loading branch information...
commit 10baa5d1883c5eed8042982b5bbedd2e208cc867 1 parent 308a33d
Andrey Moiseev authored
11 res/layout-large-v11/start_screen.xml
... ... @@ -0,0 +1,11 @@
  1 +<LinearLayout
  2 + xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="fill_parent"
  4 + android:layout_height="fill_parent"
  5 + android:orientation="vertical"
  6 + android:gravity="center">
  7 + <ru.o2genum.howtosay.StartScreenView
  8 + android:id="@+id/start_screen_view"
  9 + android:layout_width="wrap_content"
  10 + android:layout_height="wrap_content"/>
  11 +</LinearLayout>
48 res/layout-large-v11/start_screen_view.xml
... ... @@ -0,0 +1,48 @@
  1 +<LinearLayout
  2 + xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:id="@+id/start_screen_layout"
  4 + android:layout_width="fill_parent"
  5 + android:layout_height="fill_parent"
  6 + android:orientation="horizontal">
  7 + <LinearLayout
  8 + android:layout_width="wrap_content"
  9 + android:layout_height="fill_parent"
  10 + android:layout_weight="0.5"
  11 + android:orientation="vertical">
  12 + <TextView
  13 + android:id="@+id/pronunciations_total_num_view"
  14 + android:layout_width="fill_parent"
  15 + android:layout_height="wrap_content"
  16 + android:gravity="right"
  17 + android:textSize="40dp"
  18 + android:text="10234325"/>
  19 + <TextView
  20 + android:id="@+id/words_total_num_view"
  21 + android:layout_width="fill_parent"
  22 + android:layout_height="wrap_content"
  23 + android:gravity="right"
  24 + android:textSize="40dp"
  25 + android:text="900056"/>
  26 + </LinearLayout>
  27 + <LinearLayout
  28 + android:layout_width="wrap_content"
  29 + android:layout_height="fill_parent"
  30 + android:layout_weight="0.5"
  31 + android:orientation="vertical"
  32 + android:layout_marginLeft="10dp">
  33 + <TextView
  34 + android:layout_width="fill_parent"
  35 + android:layout_height="wrap_content"
  36 + android:layout_weight="0.5"
  37 + android:gravity="left"
  38 + android:textSize="28dp"
  39 + android:text="@string/start_screen_pronunciations"/>
  40 + <TextView
  41 + android:layout_width="fill_parent"
  42 + android:layout_height="wrap_content"
  43 + android:layout_weight="0.5"
  44 + android:gravity="left"
  45 + android:textSize="28dp"
  46 + android:text="@string/start_screen_words"/>
  47 + </LinearLayout>
  48 +</LinearLayout>
3  res/values-ru/strings.xml
@@ -37,6 +37,9 @@
37 37 <item quantity="one">1 произношение</item>
38 38 <item quantity="other">%d произн.</item>
39 39 </plurals>
  40 + <!-- Start screen -->
  41 + <string name="start_screen_pronunciations">произношений</string>
  42 + <string name="start_screen_words">слов</string>
40 43 <string name="search_for_pronunciations">Найти произношения</string>
41 44 <!-- Set API key activity -->
42 45 <string name="set_button">Установить</string>
2  res/values/strings.xml
@@ -37,6 +37,8 @@
37 37 <item quantity="one">1 pronunciation</item>
38 38 <item quantity="other">%d pronunciations</item>
39 39 </plurals>
  40 + <string name="start_screen_pronunciations">pronunciations</string>
  41 + <string name="start_screen_words">words</string>
40 42 <string name="search_for_pronunciations">Search for pronunciations</string>
41 43 <!-- Set API key activity -->
42 44 <string name="set_button">Set</string>
3  src/ru/o2genum/howtosay/DashboardActivity.java
@@ -191,6 +191,9 @@ public void initializeUI() {
191 191 if(is11Plus() && hasLargeScreen()) {
192 192 // Honeycomb
193 193 content = (LinearLayout) findViewById(R.id.content);
  194 + inflater.inflate(R.layout.start_screen, content, true);
  195 + StartScreenView ssv = (StartScreenView) content
  196 + .findViewById(R.id.start_screen_view);
194 197
195 198 final SearchView sv = (SearchView) findViewById(R.id.searchview);
196 199 searchView = sv;
71 src/ru/o2genum/howtosay/DashboardActivity.java~
@@ -59,6 +59,7 @@ import android.widget.Toast;
59 59 import ru.o2genum.forvo.Pronunciation;
60 60 import ru.o2genum.forvo.Word;
61 61 import ru.o2genum.forvo.WordAndPronunciation;
  62 +import ru.o2genum.forvo.User;
62 63
63 64 import com.commonsware.cwac.endless.EndlessAdapter;
64 65
@@ -137,12 +138,49 @@ public class DashboardActivity extends BaseActivity
137 138
138 139 if(wordsTab.isSelected()) {
139 140 wordListView = new ListView(this);
  141 + wordListView.setOnItemClickListener(
  142 + new AdapterView.OnItemClickListener() {
  143 + @Override
  144 + public void onItemClick(AdapterView<?> parent, View view,
  145 + int position, long id) {
  146 + EndlessWordAdapterLargeScreen a =
  147 + (EndlessWordAdapterLargeScreen) parent.getAdapter();
  148 + if(!(a.getItemViewType(position) ==
  149 + Adapter.IGNORE_ITEM_VIEW_TYPE)) {
  150 + playSound(
  151 + ((WordAndPronunciation) a.getItem(position))
  152 + .getPronunciation()
  153 + .getAudioURL(Pronunciation.AudioFormat.MP3)
  154 + .toString(), view);
  155 + } else {
  156 + // Pending view was clicked
  157 + }
  158 + }
  159 + });
140 160 wordListView.setAdapter(endlessWordAdapter);
141 161 content.addView(wordListView);
142 162 } else if(pronunciationsTab.isSelected()) {
143 163 pronunciationListView = new ListView(this);
144 164 pronunciationListView.setAdapter(
145 165 endlessPronunciationAdapter);
  166 + pronunciationListView
  167 + .setOnItemClickListener(new AdapterView.OnItemClickListener() {
  168 + @Override
  169 + public void onItemClick(AdapterView<?> parent, View view,
  170 + int position, long id) {
  171 + EndlessPronunciationAdapterLargeScreen a =
  172 + (EndlessPronunciationAdapterLargeScreen) parent.getAdapter();
  173 + if(!(a.getItemViewType(position) ==
  174 + Adapter.IGNORE_ITEM_VIEW_TYPE)) {
  175 + playSound(
  176 + ((Pronunciation) a.getItem(position))
  177 + .getAudioURL(Pronunciation.AudioFormat.MP3)
  178 + .toString(), view);
  179 + } else {
  180 + // Pending view was clicked
  181 + }
  182 + }
  183 + });
146 184 content.addView(pronunciationListView);
147 185 } else if(setApiKeyTab.isSelected()) {
148 186 onSetApiKeyTabClick();
@@ -406,7 +444,8 @@ public class DashboardActivity extends BaseActivity
406 444
407 445 public View getView(int position, View convertView, ViewGroup parent) {
408 446 if(convertView == null) {
409   - convertView = (View) inflater.inflate(R.layout.list_item, null);
  447 + convertView = (View) inflater.inflate(R.layout.word_list_item,
  448 + null);
410 449 }
411 450 TextView wordView = (TextView) convertView
412 451 .findViewById(R.id.wordview);
@@ -414,10 +453,12 @@ public class DashboardActivity extends BaseActivity
414 453 .getOriginal());
415 454 TextView pronunciationsNumberView = (TextView) convertView
416 455 .findViewById(R.id.pronunciations_number_view);
417   - pronunciationsNumberView.setText((CharSequence) (
418   - /// new Integer(getItem(position)
419   - .getWord().getPronunciationsNumber()).toString() +
420   - " произн."));
  456 + int numPronunciations = getItem(position).getWord()
  457 + .getPronunciationsNumber();
  458 + pronunciationsNumberView.setText((CharSequence)
  459 + String.format(getResources()
  460 + .getQuantityString(R.plurals.pronunciation_s,
  461 + numPronunciations), numPronunciations));
421 462 return convertView;
422 463 }
423 464 }
@@ -496,15 +537,31 @@ public class DashboardActivity extends BaseActivity
496 537
497 538 public View getView(int position, View convertView, ViewGroup parent) {
498 539 if(convertView == null) {
499   - convertView = (View) inflater.inflate(R.layout.list_item, null);
  540 + convertView = (View) inflater
  541 + .inflate(R.layout.pronunciation_list_item, null);
500 542 }
501 543 TextView langView = (TextView) convertView
502   - .findViewById(R.id.wordview);
  544 + .findViewById(R.id.languageview);
503 545 langView.setText((CharSequence)
504 546 (getLocalizedLanguageName(getItem(position)
505 547 .getLanguage()
506 548 .getCode(),
507 549 getItem(position).getLanguage().getLanguageName())));
  550 + TextView etcView = (TextView) convertView
  551 + .findViewById(R.id.etc_view);
  552 + etcView.setText((CharSequence) (
  553 + getLocalizedCountryName(getItem(position)
  554 + .getUser().getCountry()) + ", " +
  555 + getItem(position).getUser().getUserName() +
  556 + " (" + (getItem(position).getUser().getSex() ==
  557 + User.Sex.Male ? getString(R.string.male) :
  558 + getString(R.string.female)) + ")"));
  559 + TextView rateView = (TextView) convertView
  560 + .findViewById(R.id.rate_view);
  561 + int rate = getItem(position).getRate();
  562 + String rateString = new Integer(rate).toString();
  563 + rateView.setText((CharSequence) (rate > 0 ? "+" + rateString :
  564 + rateString));
508 565 return convertView;
509 566 }
510 567 }
14 src/ru/o2genum/howtosay/SidebarItemView.java
... ... @@ -1,3 +1,17 @@
  1 +/*
  2 + Copyright (c) 2011, Andrey Moiseev
  3 +
  4 + Licensed under the Apache License, Version 2.0 (the "License"); you may
  5 + not use this file except in compliance with the License. You may obtain
  6 + a copy of the License at
  7 + http://www.apache.org/licenses/LICENSE-2.0
  8 + Unless required by applicable law or agreed to in writing, software
  9 + distributed under the License is distributed on an "AS IS" BASIS,
  10 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11 + See the License for the specific language governing permissions and
  12 + limitations under the License.
  13 +*/
  14 +
1 15 package ru.o2genum.howtosay;
2 16
3 17 import android.content.Context;
62 src/ru/o2genum/howtosay/SidebarItemView.java~
... ... @@ -0,0 +1,62 @@
  1 +package ru.o2genum.howtosay;
  2 +
  3 +import android.content.Context;
  4 +import android.util.AttributeSet;
  5 +import android.view.animation.Animation;
  6 +import android.view.animation.AnimationUtils;
  7 +import android.view.LayoutInflater;
  8 +import android.view.View;
  9 +import android.view.ViewGroup;
  10 +import android.widget.ImageView;
  11 +import android.widget.LinearLayout;
  12 +import android.widget.TextView;
  13 +
  14 +public class SidebarItemView extends LinearLayout {
  15 + Context context;
  16 + View v;
  17 + ImageView iv;
  18 + TextView tv;
  19 + AttributeSet attrs;
  20 + boolean selected = false;
  21 + final String NAMESPACE =
  22 + "http://schemas.android.com/apk/res/ru.o2genum.howtosay";
  23 +
  24 + public SidebarItemView(Context context, AttributeSet attrs, int defStyle) {
  25 + super(context, attrs, defStyle);
  26 + this.context = context;
  27 + this.attrs = attrs;
  28 + loadView();
  29 + }
  30 +
  31 + public SidebarItemView(Context context, AttributeSet attrs) {
  32 + super(context, attrs);
  33 + this.context = context;
  34 + this.attrs = attrs;
  35 + loadView();
  36 + }
  37 +
  38 + private void loadView() {
  39 + LayoutInflater inflater = (LayoutInflater)
  40 + context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  41 + v = (View) inflater.inflate(R.layout.sidebar_item, this, true);
  42 + iv = (ImageView) v.findViewById(R.id.imageview);
  43 + iv.setImageResource(attrs.getAttributeResourceValue(NAMESPACE,
  44 + "icon", 0));
  45 + tv = (TextView) v.findViewById(R.id.textview);
  46 + tv.setText(attrs.getAttributeResourceValue(NAMESPACE, "text", 0));
  47 + }
  48 +
  49 + public void setSelected(boolean selected) {
  50 + this.selected = selected;
  51 + if(selected) {
  52 + v.setBackgroundResource(
  53 + R.drawable.sidebar_item_selected_background);
  54 + } else {
  55 + v.setBackgroundResource(0);
  56 + }
  57 + }
  58 +
  59 + public boolean isSelected() {
  60 + return selected;
  61 + }
  62 +}
93 src/ru/o2genum/howtosay/StartScreenView.java
... ... @@ -0,0 +1,93 @@
  1 +/*
  2 + Copyright (c) 2011, Andrey Moiseev
  3 +
  4 + Licensed under the Apache License, Version 2.0 (the "License"); you may
  5 + not use this file except in compliance with the License. You may obtain
  6 + a copy of the License at
  7 + http://www.apache.org/licenses/LICENSE-2.0
  8 + Unless required by applicable law or agreed to in writing, software
  9 + distributed under the License is distributed on an "AS IS" BASIS,
  10 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11 + See the License for the specific language governing permissions and
  12 + limitations under the License.
  13 +*/
  14 +
  15 +package ru.o2genum.howtosay;
  16 +
  17 +import android.content.Context;
  18 +import android.os.AsyncTask;
  19 +import android.util.AttributeSet;
  20 +import android.view.animation.Animation;
  21 +import android.view.animation.AnimationUtils;
  22 +import android.view.LayoutInflater;
  23 +import android.view.View;
  24 +import android.view.ViewGroup;
  25 +import android.widget.LinearLayout;
  26 +import android.widget.TextView;
  27 +
  28 +import ru.o2genum.forvo.Word;
  29 +
  30 +public class StartScreenView extends LinearLayout {
  31 +
  32 + Animation animation;
  33 + LayoutInflater inflater;
  34 + Context context;
  35 + TextView pronunciationsTotalNumberView,
  36 + wordsTotalNumberView;
  37 +
  38 + public StartScreenView(Context context, AttributeSet attrs) {
  39 + super(context, attrs);
  40 + this.context = context;
  41 + initializeUI();
  42 + }
  43 +
  44 + public StartScreenView(Context context, AttributeSet attrs,
  45 + int defStyle) {
  46 + super(context, attrs, defStyle);
  47 + this.context = context;
  48 + initializeUI();
  49 + }
  50 +
  51 + private void initializeUI() {
  52 + setVisibility(View.INVISIBLE);
  53 + inflater = (LayoutInflater) context.getSystemService(
  54 + Context.LAYOUT_INFLATER_SERVICE);
  55 + View v = inflater.inflate(R.layout.start_screen_view, this, true);
  56 + pronunciationsTotalNumberView = (TextView)
  57 + v.findViewById(R.id.pronunciations_total_num_view);
  58 + wordsTotalNumberView = (TextView)
  59 + v.findViewById(R.id.words_total_num_view);
  60 + AnimationUtils au = new AnimationUtils();
  61 + animation = au.loadAnimation(context, android.R.anim.fade_in);
  62 + new LoadDataTask().execute();
  63 + }
  64 +
  65 + class LoadDataTask extends AsyncTask<Void, Void, int[]> {
  66 + @Override
  67 + protected int[] doInBackground(Void ... v) {
  68 + Word word = new Word(null);
  69 + int data[] = new int[3];
  70 + data[0] = 1; // OK
  71 + try {
  72 + data[1] = word.getTotalPronunciations();
  73 + data[2] = word.getTotalPronouncedWords();
  74 + } catch (Exception ex) {
  75 + data[0] = 0; // NOT OK
  76 + ex.printStackTrace();
  77 + }
  78 + return data;
  79 + }
  80 +
  81 + @Override
  82 + protected void onPostExecute(int data[]) {
  83 + if(data[0] == 0)
  84 + return;
  85 + pronunciationsTotalNumberView.setText(
  86 + new Integer(data[1]).toString());
  87 + wordsTotalNumberView.setText(
  88 + new Integer(data[2]).toString());
  89 + StartScreenView.this.setVisibility(View.VISIBLE);
  90 + StartScreenView.this.startAnimation(animation);
  91 + }
  92 + }
  93 +}

0 comments on commit 10baa5d

Please sign in to comment.
Something went wrong with that request. Please try again.