Commit 07b12075 authored by Kevin Whitaker's avatar Kevin Whitaker

Change default font to something larger and easier to read. Implement...

Change default font to something larger and easier to read. Implement RecyclerView for Campaign screen. Make simple realm objects have constructors for quick access.
parent 9640ffb2
...@@ -86,10 +86,12 @@ ...@@ -86,10 +86,12 @@
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" /> <orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-v4-22.0.0" level="project" /> <orderEntry type="library" exported="" name="support-v4-22.0.0" level="project" />
<orderEntry type="library" exported="" name="android-holo-graph-0.1.0" level="project" />
<orderEntry type="library" exported="" name="calligraphy-2.0.2" level="project" /> <orderEntry type="library" exported="" name="calligraphy-2.0.2" level="project" />
<orderEntry type="library" exported="" name="realm-android-0.80.1" level="project" /> <orderEntry type="library" exported="" name="realm-android-0.80.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" /> <orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.0.0" level="project" /> <orderEntry type="library" exported="" name="appcompat-v7-22.0.0" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-21.0.3" level="project" /> <orderEntry type="library" exported="" name="recyclerview-v7-21.0.3" level="project" />
</component> </component>
</module> </module>
\ No newline at end of file
...@@ -42,4 +42,6 @@ dependencies { ...@@ -42,4 +42,6 @@ dependencies {
compile 'io.realm:realm-android:0.80.1' compile 'io.realm:realm-android:0.80.1'
compile 'uk.co.chrisjenx:calligraphy:2.0.2' compile 'uk.co.chrisjenx:calligraphy:2.0.2'
compile 'com.android.support:recyclerview-v7:21.0.+' compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'com.android.support:cardview-v7:21.0.+'
compile 'org.quanqi:android-holo-graph:0.1.0'
} }
package com.eyecreate.miceandmystics.miceandmystics; package com.eyecreate.miceandmystics.miceandmystics;
import android.content.Context; import android.app.AlertDialog;
import android.support.v7.app.ActionBarActivity; import android.content.DialogInterface;
import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.ContextThemeWrapper;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; import android.widget.EditText;
import com.eyecreate.miceandmystics.miceandmystics.adapters.CampaignAdapter;
public class CampaignActivity extends ActionBarActivity { public class CampaignActivity extends RecyclerViewActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_campaign);
getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.mipmap.ic_launcher); getSupportActionBar().setIcon(R.mipmap.ic_launcher);
} getSupportActionBar().setDisplayShowTitleEnabled(false);
setLayoutManager(new LinearLayoutManager(this));
@Override setAdapter(new CampaignAdapter());
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
} }
@Override @Override
...@@ -39,6 +40,19 @@ public class CampaignActivity extends ActionBarActivity { ...@@ -39,6 +40,19 @@ public class CampaignActivity extends ActionBarActivity {
//noinspection SimplifiableIfStatement //noinspection SimplifiableIfStatement
if (id == R.id.action_add_campaign) { if (id == R.id.action_add_campaign) {
final EditText newName = new EditText(new ContextThemeWrapper(this,R.style.editTextDialogTheme));
newName.setTypeface(Typeface.createFromAsset(getAssets(),"ArchitectsDaughter.ttf"));
AlertDialog addDialog = new AlertDialog.Builder(this,R.style.dialogTheme)
.setMessage("Please give your new campaign a unique name:")
.setView(newName)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
((CampaignAdapter) getAdapter()).addItem(newName.getText().toString());
}
})
.create();
addDialog.show();
return true; return true;
} }
......
package com.eyecreate.miceandmystics.miceandmystics; package com.eyecreate.miceandmystics.miceandmystics;
import android.app.Application; import android.app.Application;
import io.realm.Realm;
import uk.co.chrisjenx.calligraphy.CalligraphyConfig; import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
public class MiceAndMysticsApplication extends Application { public class MiceAndMysticsApplication extends Application {
private static MiceAndMysticsApplication singletonApplication;
private static Realm singletonRealm;
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
//TODO:init realm here singletonApplication = this;
singletonRealm = Realm.getInstance(this);
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder() CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("Eadui.ttf") .setDefaultFontPath("ArchitectsDaughter.ttf")
.setFontAttrId(R.attr.fontPath) .setFontAttrId(R.attr.fontPath)
.build() .build()
); );
} }
public static MiceAndMysticsApplication getInstance() {
return singletonApplication;
}
public static Realm getRealmInstance() {
return singletonRealm;
}
} }
/***
Copyright (c) 2008-2015 CommonsWare, LLC
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.
From _The Busy Coder's Guide to Android Development_
http://commonsware.com/Android
*/
package com.eyecreate.miceandmystics.miceandmystics;
import android.content.Context;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.RecyclerView;
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;
public class RecyclerViewActivity extends ActionBarActivity {
private RecyclerView rv=null;
public void setAdapter(RecyclerView.Adapter adapter) {
getRecyclerView().setAdapter(adapter);
}
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
public RecyclerView.Adapter getAdapter() {
return(getRecyclerView().getAdapter());
}
public void setLayoutManager(RecyclerView.LayoutManager mgr) {
getRecyclerView().setLayoutManager(mgr);
}
public RecyclerView getRecyclerView() {
if (rv==null) {
rv=new RecyclerView(this);
rv.setHasFixedSize(true);
setContentView(rv);
}
return(rv);
}
}
package com.eyecreate.miceandmystics.miceandmystics.adapters;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import com.eyecreate.miceandmystics.miceandmystics.MiceAndMysticsApplication;
import com.eyecreate.miceandmystics.miceandmystics.R;
import com.eyecreate.miceandmystics.miceandmystics.viewholders.Campaign;
import io.realm.RealmResults;
public class CampaignAdapter extends RecyclerView.Adapter<Campaign> {
LayoutInflater inflater;
RealmResults<com.eyecreate.miceandmystics.miceandmystics.model.Campaign> campaigns;
public CampaignAdapter() {
campaigns = MiceAndMysticsApplication.getRealmInstance().where(com.eyecreate.miceandmystics.miceandmystics.model.Campaign.class).findAll();
}
@Override
public Campaign onCreateViewHolder(ViewGroup parent, int viewType) {
if(inflater == null) inflater = (LayoutInflater)parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
return new Campaign(inflater.inflate(R.layout.item_campaign,parent,false),this);
}
@Override
public void onBindViewHolder(Campaign holder, int position) {
holder.bindModel(campaigns.get(position));
}
public void fullRefresh() {
notifyDataSetChanged();
}
public void addItem(String campaignName) {
MiceAndMysticsApplication.getRealmInstance().beginTransaction();
com.eyecreate.miceandmystics.miceandmystics.model.Campaign campaign = new com.eyecreate.miceandmystics.miceandmystics.model.Campaign();
campaign.setCampaignName(campaignName);
MiceAndMysticsApplication.getRealmInstance().copyToRealm(campaign);
MiceAndMysticsApplication.getRealmInstance().commitTransaction();
fullRefresh();
}
public void removeItem(String campaignName) {
com.eyecreate.miceandmystics.miceandmystics.model.Campaign campaign = MiceAndMysticsApplication.getRealmInstance()
.where(com.eyecreate.miceandmystics.miceandmystics.model.Campaign.class)
.equalTo("campaignName",campaignName)
.findFirst();
MiceAndMysticsApplication.getRealmInstance().beginTransaction();
campaign.removeFromRealm();
MiceAndMysticsApplication.getRealmInstance().commitTransaction();
fullRefresh();
}
@Override
public int getItemCount() {
return campaigns.size();
}
}
...@@ -7,6 +7,10 @@ public class Ability extends RealmObject { ...@@ -7,6 +7,10 @@ public class Ability extends RealmObject {
@PrimaryKey @PrimaryKey
private String abilityName; private String abilityName;
public Ability() {}
public Ability(String abilityName) {setAbilityName(abilityName);}
public String getAbilityName() { public String getAbilityName() {
return abilityName; return abilityName;
} }
......
...@@ -7,6 +7,10 @@ public class Achievement extends RealmObject { ...@@ -7,6 +7,10 @@ public class Achievement extends RealmObject {
@PrimaryKey @PrimaryKey
private String achievementName; private String achievementName;
public Achievement() {}
public Achievement(String achievementName) {setAchievementName(achievementName);}
public String getAchievementName() { public String getAchievementName() {
return achievementName; return achievementName;
} }
......
...@@ -8,6 +8,10 @@ public class BackpackItem extends RealmObject { ...@@ -8,6 +8,10 @@ public class BackpackItem extends RealmObject {
@PrimaryKey @PrimaryKey
private String itemName; private String itemName;
public BackpackItem() {}
public BackpackItem(String itemName) {setItemName(itemName);}
public String getItemName() { public String getItemName() {
return itemName; return itemName;
} }
......
...@@ -7,6 +7,10 @@ public class Player extends RealmObject { ...@@ -7,6 +7,10 @@ public class Player extends RealmObject {
@PrimaryKey @PrimaryKey
private String playerName; private String playerName;
public Player() {}
public Player(String playerName) {setPlayerName(playerName);}
public String getPlayerName() { public String getPlayerName() {
return playerName; return playerName;
} }
......
package com.eyecreate.miceandmystics.miceandmystics.viewholders;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Build;
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import com.echo.holographlibrary.PieGraph;
import com.eyecreate.miceandmystics.miceandmystics.R;
import com.eyecreate.miceandmystics.miceandmystics.adapters.CampaignAdapter;
public class Campaign extends RecyclerView.ViewHolder implements View.OnClickListener,View.OnLongClickListener {
CampaignAdapter adapter;
TextView campaignName;
PieGraph characterGraph;
public Campaign(View itemView,CampaignAdapter adapter) {
super(itemView);
this.adapter = adapter;
campaignName = (TextView) itemView.findViewById(R.id.campagin_name);
characterGraph = (PieGraph) itemView.findViewById(R.id.campaign_characters_graph);
itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
itemView.setOnTouchListener(new View.OnTouchListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean onTouch(View v, MotionEvent event) {
v
.findViewById(R.id.campaign_content)
.getBackground()
.setHotspot(event.getX(), event.getY());
return(false);
}
});
}
}
@Override
public void onClick(View view) {
//TODO:implement next screen
}
public void bindModel(com.eyecreate.miceandmystics.miceandmystics.model.Campaign campaign) {
campaignName.setText(campaign.getCampaignName());
}
@Override
public boolean onLongClick(View view) {
AlertDialog removeDialog = new AlertDialog.Builder(view.getContext(),R.style.dialogTheme)
.setMessage("Do you want to remove campaign: "+campaignName.getText()+"?")
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
})
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
adapter.removeItem((String) campaignName.getText());
}
})
.create();
removeDialog.show();
return true;
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".CampaignActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/campaign_list"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
app:cardUseCompatPadding="true"
app:cardElevation="4dp"
android:foreground="?android:attr/selectableItemBackground"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/campaign_content"
android:background="@color/parchment_yellow">
<com.echo.holographlibrary.PieGraph
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/campaign_characters_graph"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:layout_gravity="center_vertical"
android:id="@+id/campagin_name"/>
</LinearLayout>
</android.support.v7.widget.CardView>
\ No newline at end of file
<resources> <resources>
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat"> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/blood_red</item> <item name="colorPrimary">@color/blood_red</item>
<item name="colorPrimaryDark">@color/dark_red</item> <item name="colorPrimaryDark">@color/dark_red</item>
<item name="android:windowBackground">@color/wood_brown</item> <item name="android:windowBackground">@color/wood_brown</item>
...@@ -14,4 +14,17 @@ ...@@ -14,4 +14,17 @@
<item name="android:colorBackground">@color/blood_red</item> <item name="android:colorBackground">@color/blood_red</item>
</style> </style>
<style name="dialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="android:background">@color/parchment_yellow</item>
<item name="colorPrimary">@color/blood_red</item>
<item name="colorPrimaryDark">@color/dark_red</item>
<item name="colorAccent">@color/wood_brown</item>
<item name="android:textColorPrimary">@android:color/black</item>
</style>
<style name="editTextDialogTheme" parent="Widget.AppCompat.EditText">
<item name="colorAccent">@color/wood_brown</item>
<item name="android:textColorPrimary">@android:color/black</item>
</style>
</resources> </resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment