mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 22:07:56 +01:00
Android: language selection
This commit is contained in:
parent
b42b195245
commit
323b95ad7a
@ -3,10 +3,10 @@ package com.sismics.docs.activity;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
|
|
||||||
import com.sismics.docs.R;
|
import com.sismics.docs.R;
|
||||||
|
import com.sismics.docs.adapter.LanguageAdapter;
|
||||||
import com.sismics.docs.adapter.TagAutoCompleteAdapter;
|
import com.sismics.docs.adapter.TagAutoCompleteAdapter;
|
||||||
import com.sismics.docs.ui.view.TagsCompleteTextView;
|
import com.sismics.docs.ui.view.TagsCompleteTextView;
|
||||||
import com.sismics.docs.util.PreferenceUtil;
|
import com.sismics.docs.util.PreferenceUtil;
|
||||||
@ -39,8 +39,7 @@ public class DocumentEditActivity extends ActionBarActivity {
|
|||||||
getSupportActionBar().setHomeButtonEnabled(true);
|
getSupportActionBar().setHomeButtonEnabled(true);
|
||||||
|
|
||||||
Spinner languageSpinner = (Spinner) findViewById(R.id.languageSpinner);
|
Spinner languageSpinner = (Spinner) findViewById(R.id.languageSpinner);
|
||||||
languageSpinner.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item,
|
languageSpinner.setAdapter(new LanguageAdapter(this));
|
||||||
new String[] { "French", "English", "Japanese" }));
|
|
||||||
|
|
||||||
JSONObject tags = PreferenceUtil.getCachedJson(this, PreferenceUtil.PREF_CACHED_TAGS_JSON);
|
JSONObject tags = PreferenceUtil.getCachedJson(this, PreferenceUtil.PREF_CACHED_TAGS_JSON);
|
||||||
if (tags == null) {
|
if (tags == null) {
|
||||||
|
@ -0,0 +1,91 @@
|
|||||||
|
package com.sismics.docs.adapter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.BaseAdapter;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.sismics.docs.R;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Languages adapter.
|
||||||
|
*
|
||||||
|
* @author bgamard.
|
||||||
|
*/
|
||||||
|
public class LanguageAdapter extends BaseAdapter {
|
||||||
|
/**
|
||||||
|
* Context.
|
||||||
|
*/
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
private List<Language> languageList;
|
||||||
|
|
||||||
|
public LanguageAdapter(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
this.languageList = new ArrayList<>();
|
||||||
|
languageList.add(new Language("fra", R.string.language_french, R.drawable.fra));
|
||||||
|
languageList.add(new Language("eng", R.string.language_english, R.drawable.eng));
|
||||||
|
languageList.add(new Language("jpn", R.string.language_japanese, R.drawable.jpn));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return languageList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Language getItem(int position) {
|
||||||
|
if (position >= languageList.size()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return languageList.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getItemId(int position) {
|
||||||
|
return getItem(position).id.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View view, ViewGroup parent) {
|
||||||
|
if (view == null) {
|
||||||
|
LayoutInflater vi = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
view = vi.inflate(R.layout.language_list_item, parent, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill the view
|
||||||
|
Language language = getItem(position);
|
||||||
|
TextView languageTextView = (TextView) view.findViewById(R.id.languageTextView);
|
||||||
|
languageTextView.setText(context.getText(language.name));
|
||||||
|
languageTextView.setCompoundDrawablesWithIntrinsicBounds(language.drawable, 0, 0, 0);
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A language.
|
||||||
|
*/
|
||||||
|
private static class Language {
|
||||||
|
private String id;
|
||||||
|
private int name;
|
||||||
|
private int drawable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A language.
|
||||||
|
*
|
||||||
|
* @param id Language ID
|
||||||
|
* @param name Language name
|
||||||
|
* @param drawable Language drawable
|
||||||
|
*/
|
||||||
|
public Language(String id, int name, int drawable) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.drawable = drawable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
docs-android/app/src/main/res/layout/language_list_item.xml
Normal file
15
docs-android/app/src/main/res/layout/language_list_item.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/languageTextView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:drawableLeft="@drawable/fra"
|
||||||
|
android:drawableStart="@drawable/fra"
|
||||||
|
android:text="French"
|
||||||
|
android:drawablePadding="8dp"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textColor="#666"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:ellipsize="end"/>
|
@ -71,6 +71,9 @@
|
|||||||
<string name="pref_clear_history_summary">Wipe the recent search suggestions</string>
|
<string name="pref_clear_history_summary">Wipe the recent search suggestions</string>
|
||||||
<string name="pref_clear_history_success">Search history cleared</string>
|
<string name="pref_clear_history_success">Search history cleared</string>
|
||||||
<string name="pref_cache_size">Cache size</string>
|
<string name="pref_cache_size">Cache size</string>
|
||||||
|
<string name="language_french">French</string>
|
||||||
|
<string name="language_english">English</string>
|
||||||
|
<string name="language_japanese">Japanese</string>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user