Tuesday, 28 July 2015

http://techworldfx.blogspot.in/

How to use GitHub with Android Studio


https://www.londonappdeveloper.com/how-to-use-git-hub-with-android-studio/

How to use GitHub with Android Studio

UPDATE: This is an old tutorial written for Android Studio Beta. Since then there have been some updates and (although the below will still work) you may find it quicker to follow my updated tutorial How to use GitHub with Android Studio 1.x.
This article will explain how to use GitHub with Android Studio.
Video Demonstration
Firstly, let’s login to github.com and create a new repository. From the top right corner of the screen, click the + sign and select New repository.
GitHub "New repository" optionGitHub “New repository” option
Now complete the form to create a new repository called testproject. Leave the Initialize this repository with a README unticked.
GitHub create new repository formGitHub create new repository form
Next, open Android Studio and create a new project. Call your new application TestProject. Click Next to continue.
Android Studio new project windowAndroid Studio new project window
Leave the next page as default and click Next.
Android Studio "Select the form factors your app will run on" screenAndroid Studio “Select the form factors your app will run on” screen
On the Add an activity to Mobile screen select Blank Activity and click Next.
Android Studio "Add an activity to Mobile" screenAndroid Studio “Add an activity to Mobile” screen
In the next screen, leave the default activity name of MyActivity and click Finish.
Android Studio "New file options" screenAndroid Studio “New file options” screen
Your new project will open in Android Studio. On the top menu, select VCS > Import into Version Control >Create Git Repository.
Android Studio "Create Git Repository" option.Android Studio “Create Git Repository” option.
On the next screen, leave it all as default and click OK.
Android Studio "Select directory for git init" screenAndroid Studio “Select directory for git init” screen
Now use Internet Explorer and navigate to the root of your projects folder. Right click and select Git Bash (If you do not see this option, then first install Git for Windows).
When the Git bash screen appears, type:
1
git remote add origin https://github.com/[username]/[project_name].git
An example of a Git repository URL is: https://github.com/markwint/testproject.git
Entering command into Git BashEntering command into Git Bash
Then press enter. The GitHub remote will be added to your Git repository.
Next, jump back into Android Studio, right click your projects root directory and select Git > Add. This will add all your project files to your Git repository.
Android Studio "Git > Add" option Android Studio “Git > Add” option
It will seem like nothing has happened, but trust me, the project files are added.
Now right click the project name again and this time select Git > Commit Directory.
Android Studio "Commit Directory" optionAndroid Studio “Commit Directory” option
In the next screen, type a Commit Message and select Commit.
Android Studio "Commit Changes" optionAndroid Studio “Commit Changes” option
If a Code Analysis warning appears, click Commit. (Unless it’s a real project, in which case review and fix the issue before committing!)
Android Studio "Code Analysis" warningAndroid Studio “Code Analysis” warning
Now, right click the project name, select Git > Repository > Push.
Android Studio "Git Push" optionAndroid Studio “Git Push” option
Check the box Push current branch to alternative branch and leave the branch name as master. Then select push.
Android Studio "Git Push" promptAndroid Studio “Git Push” prompt
Now enter your GitHub Login (email address) and Password. Then click OK.
Android Studio GitHub Remote LoginAndroid Studio GitHub Remote Login
If it’s all good, you will see this message.
Android Studio Successful Git PushAndroid Studio Successful Git Push
Now your code is pushed to your GitHub repository. Don’t believe me? Logon and check for yourself.
GitHub repository pushed from Android StudioGitHub repository pushed from Android Studio
Hope that was helpful.

Manipulating Android tasks and back stack

Friday, 24 July 2015

MVC design pattern for android app development by using Fragments as Views and Activity as Controller

http://stackoverflow.com/questions/9069778/mvc-design-pattern-for-android-app-development-by-using-fragments-as-views-and



I was recently reading Fragments( haven't used this in my app though) and learnt that it can be used in phones app development.
I am thinking about using Fragments to implement MVC(model-view-controller) design pattern. Many argue that android development complies with MVC by default . But i do see Activities much like Views and there's definite lack of a controller when another activity is being/due to be launched. So i am thinking of using "Fragments" as "Views" with a single "Activity" as"Controller" and swap/add/remove the fragments as and when needed.
So my basic approach is like this.
1) The user interacts with the user interface (Fragments).
2) The controller (Activity) handles the event from the Fragments and passes it to a model(Backendthread / Service).
3) Model(Backendthread / Service) notifies the controller of models state change.
4) The controller (Activity) notifes the UserInterface(Fragments) which inturn notifies the User.
does my approach is rite or an unnecessary overhead or my perception about fragments is wrong?
Please clarify me.
shareedit
   
I would like to see an example of your code when you will have something working –  IamStalker Jan 30 '12 at 20:09
up vote14down voteaccepted
IMHO, fragments are the controller. The fragment's basket of widgets represents the view. Activities are an orchestration layer, determining what fragments (and their widgets) are needed in a given circumstance (e.g., one on a phone, two on a tablet) but otherwise having limited business logic.
That being said, Android and patterns like MVC don't necessarily go together. I don't think that Google's intention was to create a pure MVC framework.
shareedit

Android MVC Patterns

http://www.therealjoshua.com/2011/11/android-architecture-part-1-intro/

Android Developer header image 2

Android Architecture: Part 1, Intro

November 24th, 2011 · 11 Comments · AndroidOOP

As an Actionscript developer and having worked on numerous data-driven applications, I’ve had an Object Oriented mindset for many years now. When I first started learning Android I want to know some of the common approaches people were taking to their applications. I had questions like “What approach are people using to send data back and forth using web services?” and “What does an MVC look like in Android?” and “How are people persisting their data locally?” and “What are some of the common patterns in Android to achieve common tasks?”
Sleuth:
I began investigating what MVC looked like in Android. After spending a lot of time reading community forums like Stack Overflow and Android blogs, I frequently saw the term “View-Controller” when talking about implementing an MVC pattern. Summarizing, people were saying the Activity should function both as both the View and Controller. This idea didn’t sit with me too well. The idea of a View-Controller violates the Single Responsibility Principle. Let’s not start mixing and matching the responsibilities.
I then went on to investigate how other developers were structuring their code for handling web services. So I downloaded a popular online dating app since I knew it would be heavily web-service driven, decompiled it using dex2jar (maybe I’ll make a blog post on this process sometime), and took a look at their source code. Their approach was to make all request go through a single class. For instance, XRequest.viewUser(142) and XRequest.sendMessage(142, “hello world”) and XRequest.blockUser(142, 138). You get the idea. Again, this approach didn’t sit well with me. Not only did this approach violate the Single Responsibility Principle it also violates the Open-Closed Principle. If a new API call was to be added, they would have to go back in XRequest class and modify the code. The class was not closed to modifications and was not open to extensibility.
The Results:
Through my reading and research, I didn’t feel like I’d saw a solid or common architectural approach on Android. This series of articles will walk through building a simple application from start to finish using practices I’ve found to be very beneficial and extensible. We will explore using a strict MVC in Android, use of the State Pattern, Data Access Objects for persisting data, and Commands for sending and receiving data using a web service. The series will cover how to implement these ideas in Android and not necessarily go in depth as to why or what benefits these patterns have. I’m going to assume you know already know the benefits of MVC and such. Additionally, the order I present the topics is not the order which I would code an application but the order I find makes most sense in disussion.
Our Project:
We will use an application I wrote called “Tap Counter” for the discussion. Go ahead and grab the sources, compile it and play around with it. It’s one of those tools gate attendants use to count how many people pass by. Here’s a couple screenshots because it’s much more fun reading about code when you get to see the results it produces.
Sources

Thursday, 23 July 2015

Fragment communication design pattern

Principle of list privileges (POLP)

http://www.quizover.com/questions/principle-of-least-privilege.xhtml?qcr=www.javachamp.com


What are the benefits of "principle of least privilege"? 

A) restrains the damage and/or unauthorized information access that can occur due to intruders attacks 
B) improves application scalability 
C) improves application reliability 
D) improves application security


Answer:
 A) restrains the damage and/or unauthorized information access that can occur due to intruders attacks 
D) improves application security

Android Project

https://github.com/hemant4524/Directory

1. Login with facebook
2. Volley Network Call
3. Xml Parsing using pullparser
4. Json Parsing using GSON

Hex transparency colors in android


I'm working on implementing a wigdget transparency option for my app widget although I'm having some trouble getting the hex color values right. Being completely new to hex color transparency I searched around a bit although I couldn't find a specific answer to my question.
I want to set transparency by hex color so let's say my hex color id "#33b5e5" and I want it to be 50% transparent. Then I'll use "#8033b5e5" because 80 is 50%.
I found a useful chart here: http://www.dtp-aus.com/hexadeci.htm . With this data I managed to come up with this:
0% = #00
10% = #16
20% = #32
30% = #48
40% = #64
50% = #80
60% = #96
70% = #112
80% = #128
90% = #144
Now the issues start appearing when I get higher than 100 in hex. Hex color codes can only be 8 symbols long right? For example #11233b5e5 (80%) crashes.
What can I do to enable me to use the higher numbers aswell?
shareedit

9 Answers

up vote1048down voteaccepted
Here's a correct table of percentages to hex values. E.g. for 50% white you'd use #80FFFFFF.
  • 100% — FF
  • 95% — F2
  • 90% — E6
  • 85% — D9
  • 80% — CC
  • 75% — BF
  • 70% — B3
  • 65% — A6
  • 60% — 99
  • 55% — 8C
  • 50% — 80
  • 45% — 73
  • 40% — 66
  • 35% — 59
  • 30% — 4D
  • 25% — 40
  • 20% — 33
  • 15% — 26
  • 10% — 1A
  • 5% — 0D
  • 0% — 00