Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Kasasasu/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AreaActivity"
android:label="@string/title_activity_area" >
</activity>
<activity
android:name=".PrefActivity"
android:label="@string/title_activity_pref" >
</activity>
<activity
android:name=".CityActivity"
android:label="@string/title_activity_city" >
</activity>
</application>

</manifest>
58 changes: 58 additions & 0 deletions Kasasasu/app/src/main/java/com/example/kasasasu/AreaActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.example.kasasasu;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;


public class AreaActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_area);

// リストビューにアイテム (adapter) を追加
ListView prefListView = (ListView)findViewById(R.id.listView2);

// アイテムクリック時ののイベントを追加
prefListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view, int pos, long id) {
Intent intent = new Intent(AreaActivity.this, PrefActivity.class);
intent.putExtra("area", pos);
startActivity(intent);
}
});
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_area, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}
101 changes: 101 additions & 0 deletions Kasasasu/app/src/main/java/com/example/kasasasu/CityActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.example.kasasasu;

import android.app.Activity;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.io.IOException;
import java.util.List;
import java.util.Locale;


public class CityActivity extends Activity {

private KasasasuSQLiteOpenHelper DBHelper;
private String pref;
private String prefRoman;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_city);

Intent intent = getIntent();
pref = intent.getStringExtra("pref");

Geocoder geocoder = new Geocoder(this, Locale.US);
try{
List<Address> addressList = geocoder.getFromLocationName(pref, 1);
Address address = addressList.get(0);
Log.d("geocode", address.toString());
prefRoman = address.getAdminArea().split(" ")[0].toLowerCase();
}catch(IOException e){
e.printStackTrace();
}

Log.d("city id", pref);
String[] cities = getResources().getStringArray(getResources().getIdentifier(prefRoman + "_cities", "array", getPackageName()));

ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this, android.R.layout.simple_list_item_1, cities);

// リストビューにアイテム (adapter) を追加
ListView cityListView = (ListView)findViewById(R.id.cityListView);
cityListView.setAdapter(adapter);

// アイテムクリック時ののイベントを追加
cityListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view, int pos, long id) {
// 選択アイテムを取得
ListView listView = (ListView)parent;
String city = (String)listView.getItemAtPosition(pos);

DBHelper.add("prefecture", pref);
DBHelper.add("city", city);

Intent intent = new Intent(CityActivity.this, MainActivity.class);
intent.putExtra("fragment", 1);
startActivity(intent);

// 通知ダイアログを表示
Toast.makeText(CityActivity.this, city, Toast.LENGTH_LONG).show();
}
});

DBHelper = new KasasasuSQLiteOpenHelper(this);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_city, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}
120 changes: 62 additions & 58 deletions Kasasasu/app/src/main/java/com/example/kasasasu/FragmentSetting.java
Original file line number Diff line number Diff line change
@@ -1,93 +1,97 @@
package com.example.kasasasu;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.AdapterView;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Switch;
import java.util.ArrayList;
import java.util.HashMap;

public class FragmentSetting extends Fragment implements CompoundButton.OnCheckedChangeListener, View.OnClickListener {

public class FragmentSetting extends Fragment implements CompoundButton.OnCheckedChangeListener {
private View v;
private EditText prefectureEditText, cityEditText;
private Button saveButton;
private KasasasuSQLiteOpenHelper DBHelper;
private boolean swIsChecked;
private Activity activity;
private HashMap<String, String> settings;
private KasasasuSQLiteOpenHelper DBHelper;
private Switch switch1;
private boolean swIsChecked;
private ArrayList<Setting> settingArrayList;
private SettingAdapter adapter;
private String address;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
v = inflater.inflate(R.layout.fragment_setting, null);
prefectureEditText = (EditText)v.findViewById(R.id.prefecureText);
cityEditText = (EditText)v.findViewById(R.id.cityText);
//フラグメントのビューを取得
v = inflater.inflate(R.layout.fragment_setting2, null);

saveButton = (Button)v.findViewById(R.id.saveButton);
saveButton.setOnClickListener(this);
//MainActivityを取得
activity = getActivity();

switch1 = (Switch)v.findViewById(R.id.switch1);
switch1.setOnCheckedChangeListener(this);

//設定内容をDBから取得
DBHelper = new KasasasuSQLiteOpenHelper(getActivity());
settings = DBHelper.get();
Log.d("show", settings.toString());
if (settings.containsKey("prefecture")) prefectureEditText.setText(settings.get("prefecture"));
if (settings.containsKey("city")) cityEditText.setText(settings.get("city"));

if (settings.containsKey("textSetting") && settings.get("textSetting").equals("on")){
//Log.d("show", settings.get("prefecture"));
switch1 = (Switch)v.findViewById(R.id.switch1);
//住所文字列を設定内容から取得
address = "";
if (settings.containsKey("prefecture")) address += settings.get("prefecture");
if (settings.containsKey("city")) address += settings.get("city");

//ListViewのアダプターを生成
settingArrayList = new ArrayList<>();
if (swIsChecked) settingArrayList.add(new Setting("地域", address));
adapter = new SettingAdapter(activity, settingArrayList);

// リストビューにアイテム (adapter) を追加
ListView listView1 = (ListView)v.findViewById(R.id.listView1);
listView1.setAdapter(adapter);

// アイテムクリック時ののイベントを追加
listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view, int pos, long id) {
// 選択アイテムを取得
ListView listView = (ListView)parent;
String item = ((Setting)listView.getItemAtPosition(pos)).getName();

switch (item) {
case "地域":
//スイッチが有効状態であれば住所選択画面へ
if (swIsChecked) {
Intent intent = new Intent(activity, AreaActivity.class);
startActivity(intent);
}
break;
}
}
});

//スイッチのオン・オフをDBから取得
if (settings.containsKey("selfAreaSetting") && settings.get("selfAreaSetting").equals("true")) {
switch1.setChecked(true);
swIsChecked = true;
} else {
prefectureEditText.setFocusable(false);
prefectureEditText.setFocusableInTouchMode(false);
cityEditText.setFocusable(false);
cityEditText.setFocusableInTouchMode(false);
swIsChecked = false;
}
return v;
}

@Override
public void onStart() {
super.onStart();
}

@Override
public void onClick(View v) {
//Log.d("frag", "onclick");
boolean settingIsText = false;
String on_or_off = "off";
if (swIsChecked) {
settingIsText = true;
on_or_off = "on";
}
DBHelper.add("textSetting", on_or_off);

prefectureEditText = (EditText)getActivity().findViewById(R.id.prefecureText);
cityEditText = (EditText)getActivity().findViewById(R.id.cityText);
DBHelper.add("prefecture", prefectureEditText.getText().toString());
DBHelper.add("city", cityEditText.getText().toString());
((FragmentMain)getTargetFragment()).updateLatLon(settingIsText, prefectureEditText.getText().toString() + cityEditText.getText().toString());
}

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if ((swIsChecked = isChecked) == true) {
prefectureEditText.setFocusable(true);
prefectureEditText.setFocusableInTouchMode(true);
cityEditText.setFocusable(true);
cityEditText.setFocusableInTouchMode(true);
} else {
prefectureEditText.setFocusable(false);
prefectureEditText.setFocusableInTouchMode(false);
cityEditText.setFocusable(false);
cityEditText.setFocusableInTouchMode(false);
}
swIsChecked = isChecked;
DBHelper.add("selfAreaSetting", String.valueOf(isChecked));

if (isChecked) adapter.add(new Setting("地域", address));
else adapter.delete("地域");
adapter.notifyDataSetChanged();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.example.kasasasu;

import android.app.ActionBar;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.FragmentActivity;
Expand All @@ -21,7 +23,15 @@ protected void onCreate(Bundle savedInstanceState) {
actionBar.setDisplayUseLogoEnabled(true);

viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter( new KasasasuFragmentStatePagerAdapter( getSupportFragmentManager()));
viewPager.setAdapter(new KasasasuFragmentStatePagerAdapter(getSupportFragmentManager()));

Intent intent = getIntent();
Log.d("intent" , intent.toString());
if (intent != null) {
int fragment;
fragment = intent.getIntExtra("fragment", 0);
viewPager.setCurrentItem(fragment);
}
}

@Override
Expand Down
Loading