Google Books has a vision to digitize the world’s books. You can use the Google Books API to search content, organize an authenticated user’s personal library and modify it as well.
Books concepts
为了能够正确处理随后返回的json数据,应当理解以下四则基本概念:
Volume: A volume represents the data that Google Books hosts about a book or magazine. It is the primary resource in the Books API. All other resources in this API either contain or annotate a volume.
Bookshelf: A bookshelf is a collection of volumes. Google Books provides a set of predefined bookshelves for each user, some of which are completely managed by the user, some of which are automatically filled in based on user’s activity, and some of which are mixed. Users can create, modify or delete other bookshelves, which are always filled with volumes manually. Bookshelves can be made private or public by the user.
Note: Creating and deleting bookshelves as well as modifying privacy settings on bookshelves can currently only be done through the Google Books site.
Review: A review of a volume is a combination of a star rating and/or text. A user can submit one review per volume. Reviews are also available from outside sources and are attributed appropriately.
Reading Position: A reading position indicates the last read position in a volume for a user. A user can only have one reading position per volume. If the user has not opened that volume before, then the reading position does not exist. The reading position can store detailed position information down to the resolution of a word. This information is always private to the user.
Working with volumes
Performing a search
You can perform a volumes search by sending an HTTP GET request to the following URI:
try: result = requests.get(main_url, send_headers, proxies=proxies) except : time.sleep(5) return"[Unknown][Goodreads]Fail to request the link"
return BeautifulSoup(result.text, 'html.parser')
defTwoStrMatch(string1:str,string2:str): result = difflib.SequenceMatcher(None, string1, string2).quick_ratio() print(string1 + "====" + string2 + "====" + str(result)) return result
defGetAuthorByTitleUsingGoogleBooksAPI(Title:str): Google_Book_APIs_Head = "https://www.googleapis.com/books/v1/volumes?q=" API_KEY = "AIzaSyCdlpdS8EWgKIN6EW95fwjiLqDkkiIA8Pg" Search_Data = Title
#https://www.googleapis.com/books/v1/volumes?q=A%20Summer%20In%20Europe+intitle:keyes&key=AIzaSyCdlpdS8EWgKIN6EW95fwjiLqDkkiIA8Pg #https://www.googleapis.com/books/v1/volumes?q=a summer in europe&printType=books&intitle:a summer in europe
A service is an component that runs at the background
E.g. music play at the background
Service is not a thread
Broadcast Receiver
Receives broadcast from Android system and other apps and responses with pre-coded actions.
Apps are required to regist to get the broadcast
Example: When the battery level changes, the system broadcast a message.
Activity
Offen refer to one interface on your phone.
Primary class for interacting with user.
For example, Wechat:
When you click on the app launcher, its corresponding greeting page will be shown to you.
Android system invokes the main activity of the Wechat.
Apps that request for online payment (such as railway ticket payment) can directly reach the payment page.
Another app invokes the payment activity of Wechat.
Apps that request for “share on moments” can directly invoke the moments sharing page of Wechat.
Another app invokes the “share on moments” activity of Wechat
Back Stack
When a new activty is launched, the previous activity will be paused and sent to the top of the back stack
Life circle
Runing: The activity is on the top of the screen and gained focus. Running will not be killed.
Paused: The activity is on the top of the screen and gained focus.
Stopped: The activity is completely covered by another running activity.
Destroyed
When running short of memory, a stopped activity is more likely to get killed than a paused/running activity.
Good implementation of callback functions can make your app more robust and performant.
Possible issues with a bad implementation:
Crashing if the user receives a phone call or switches to another app while using your app.
Consuming valuable system resources when the user is not actively using it.
Losing the user’s progress if they leave your app and return to it at a later time.
Crashing or losing the user’s progress when the screen rotates between landscape and portrait orientation.
CallBack Funtions: Typical Uses
onCreate(): Initial setup, load persistent state.
onRestart(): read cached state
onStart(): reset application
onResume(): start foreground-only behaviors
onPause(): shutdown foreground-only behaviors
For example: temporarily stop UI animations.
onStop(): cache state
onDestroy(): save persistent state
The above points are very general. Carefully design your app and keep the life cycle graph in mind.
Create Activities
Create a new Activity class. Which either inherits Android.app.Activity or its subclasses.
Override Activity.onCreate().
Create a layout XML file in res/layout and use setContentView() to load this layout.
Register the new activity in AndroidManifest.xml.
If it is a main activity, you need to add a special section in the manifest file.
Activities can be started by calling the function
1
startActivity(Intent intent)
To call Activity2 Inside an activity, do:
1 2 3 4
Intent intent = new Intent(this, Activity2.class);
startActivity(intent);
The name of the target activity is not always explicitly specified. For instance, to let Android system choose an suitable activity for sending email (in Lecture 9):
1 2 3
Intent intent = new Intent(Intent.ACTION_SEND); Intent.putExtra(Intent.EXTRA_EMAIL, recipientArray); startActivity(intent);
Obtain vals from another activity
Sometimes we wish to obtain results from another activity. We need to start the activity using
1
startActivityForResult()
You must also implement the function below to get the return result
1
onActivityResult()
Closing Activities
Android will automatically manage the life cycles of your activities.
You can destroy the current activity manually by calling finish().
To finish an activity that you previously invoked with
1 2
startActivityForResult(Intent, int), use finishActivity(int requestCode)
Can be handy when you want to make sure that the user won’t return to this activity in the future.
Passing Data between Activities
Bundle and Intent is actually the same thing.
Console output
Your console output (System.out) can be seen from the “run” window in Android Studio.
You should normally use Log class instead, though:
Photon Unity Networking (PUN) is a Unity package for multiplayer games. Flexible matchmaking gets your players into rooms where objects can be synced over the network. RPCs, Custom Properties or “low level” Photon events are just some of the features. The fast and (optionally) reliable communication is done through dedicated Photon server(s), so clients don’t need to connect one to one.
相关代码可
Refer to the link below to view in the Asset Store (PUN2)
publicoverridevoidOnRoomListUpdate(List<RoomInfo> roomList) { //PhotonNetwork.countOfRooms != PhotonNetwork.GetRoomList(); Debug.Log("[Network]Room List is Updated: " + roomList.Count() + " in total");
//先清理已有的房间列表 foreach (Transform item in roomListContent) { Destroy(item.gameObject); }
for (int i = 0; i < roomList.Count(); i++) { if (roomList[i].RemovedFromList) continue; Instantiate(roomListItemPrefab, roomListContent).GetComponent<RoomListItem>().SetUp(roomList[i]); } }
//房间消息列表更新时调用(如创建了新房,已有的房间关闭) publicoverridevoidOnRoomListUpdate(List<RoomInfo> roomList) { //PhotonNetwork.countOfRooms != PhotonNetwork.GetRoomList(); Debug.Log("[Network]Room List is Updated: " + roomList.Count() + " in total");
//先清理已有的房间列表 foreach (Transform item in roomListContent) { Destroy(item.gameObject); }
for (int i = 0; i < roomList.Count(); i++) { if (roomList[i].RemovedFromList) continue; Instantiate(roomListItemPrefab, roomListContent).GetComponent<RoomListItem>().SetUp(roomList[i]); } }